Results 1 to 8 of 8
-
18th Jan 2012, 02:25 PM #1OPMember
[PHP] Small Fix
Hey Guys ,
I am using a script and need a small fix .
Normally it grabs some images from a website but at times the images are not available .
e.g :
$variable = '[img]'.$images[0].'[/img]';
Now when the image is unavailable , at times i get :
[img][/img] or [img]Array[/img]
Is there any simple function to do this :
( if the image variable is blank or (Array) , i use a custom image not available screen instead)
like :
If $variable = ("" or "Array") {
$variable = "http//site/image.png";
}
viruz99 Reviewed by viruz99 on . [PHP] Small Fix Hey Guys , I am using a script and need a small fix . Normally it grabs some images from a website but at times the images are not available . e.g : $variable = ''.$images.''; Rating: 5
-
18th Jan 2012, 02:30 PM #2MemberWebsite's:
wscripts.net damnlolscript.com lulzjet.comyou can try:
PHP Code:if(is_array($var)||$var==NULL) $image = 'image';
-
18th Jan 2012, 02:35 PM #3Respected Developer
you can simply assign a default image i.e $image and check as below:
PHP Code:$image = "http://link/to/Your_default_image.jpg";
if(isset($images[0]))
$image = $images[0];
$variable = '[img]'.$image.'[/img]';
Bots Development | Web Development | Wordpress Customization | PSD Conversion
Life has many twists and turns in it, you have to take what you are given and use it for the best.
-
18th Jan 2012, 05:34 PM #4OPMember
<?php
$images[0] ="http:/image0.jpg";
$image = "http://link/test.jpg";
if(isset($images[0]))
$image = $images[0];
$test = '[img]'.$image.'[/img]';
echo $test;
?>
------------------------------------------------------------
Not working ---
$images[0] ="";
If i leave the $images[0] blank like above , $test = [img][/img]
-
18th Jan 2012, 05:57 PM #5MemberWebsite's:
wscripts.net damnlolscript.com lulzjet.comread more about isset http://php.net/isset
if you use $images[0] =""; this mean the variable is set
try to check if is null
-
18th Jan 2012, 06:35 PM #6Retired NinJaWebsite's:
loledhard.commRaza did in correct way. Y dont u use that ?
You don't hate Justin bieber.You hate the fact you ain't Justin Bieber!
-
18th Jan 2012, 07:16 PM #7Member
This site is using a hacked database of W junction
Last edited by Gavo; 4th Jan 2015 at 02:34 PM.
-
19th Jan 2012, 12:36 AM #8Respected Developer
t3od0r for isset : Returns TRUE if var exists and has value other than NULL, FALSE otherwise.
so basically isset is already checking for NULL values but if you still wants to check for null use is_null
PHP Code:...
if(isset($images[0]) && !is_null($images[0]))
...
if($images[0])
it will show you a warning if its not set.Bots Development | Web Development | Wordpress Customization | PSD Conversion
Life has many twists and turns in it, you have to take what you are given and use it for the best.
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
OS for a small VPS
By RNBxBeatz in forum Server ManagementReplies: 11Last Post: 31st Aug 2011, 03:19 AM -
Need Small help with a Small JS code
By Netguy in forum Web Development AreaReplies: 2Last Post: 5th Nov 2010, 10:08 AM -
Small Bug?
By DeLeTeD in forum Feedback and SuggestionsReplies: 8Last Post: 9th Oct 2010, 08:16 AM -
What's with the small i's?
By Gempis in forum General DiscussionReplies: 14Last Post: 30th Jun 2010, 06:05 PM -
Small GFX Help
By Cooper in forum Community CooperativeReplies: 0Last Post: 19th Apr 2010, 09:52 PM
themaManager - edit and manage...
Version 4.04 released. Open older version (or...