Status
Not open for further replies.

viruz99

Active Member
1,547
2010
96
0
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 = '
';

Now when the image is unavailable , at times i get :

or


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";

}





 
7 comments
you can simply assign a default image i.e $image and check as below:

PHP:
$image = "http://link/to/Your_default_image.jpg";
if(isset($images[0]))
  $image = $images[0];

$variable = '[img]'.$image.'[/img]';

if($images[0]) its checking if there is any image here then change $image value to that else keep your default value.
 
<?php

$images[0] ="http:/image0.jpg";
$image = "http://link/test.jpg";

if(isset($images[0]))
$image = $images[0];

$test = '
';

echo $test;

?>

------------------------------------------------------------

Not working ---

$images[0] ="";
If i leave the $images[0] blank like above , $test =






 
If sometimes you get

PHP:
 [img]Array[/img]

You are making more than 1 match & need to use a foreach for each image found along with mRAza code.
 
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:
...
if(isset($images[0]) && !is_null($images[0]))
...

or just use
if($images[0])
it will show you a warning if its not set.
 
Last edited:
Status
Not open for further replies.
Back
Top