Activity Stream
48,167 MEMBERS
6883 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 8 of 8
  1.     
    #1
    Member

    Default [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

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    wscripts.net damnlolscript.com lulzjet.com
    you can try:
    PHP Code: 
    if(is_array($var)||$var==NULL$image 'image'

  4.     
    #3
    Respected 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]'
    if($images[0]) its checking if there is any image here then change $image value to that else keep your default value.
    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.

  5.     
    #4
    Member
    <?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]






  6.     
    #5
    Member
    Website's:
    wscripts.net damnlolscript.com lulzjet.com
    read more about isset http://php.net/isset

    if you use $images[0] =""; this mean the variable is set

    try to check if is null

  7.     
    #6
    Retired NinJa
    Website's:
    loledhard.com
    mRaza did in correct way. Y dont u use that ?



    You don't hate Justin bieber.You hate the fact you ain't Justin Bieber!

  8.     
    #7
    Member
    This site is using a hacked database of W junction
    Last edited by Gavo; 4th Jan 2015 at 02:34 PM.

  9.     
    #8
    Respected 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]))
    ... 
    or just use
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. OS for a small VPS
    By RNBxBeatz in forum Server Management
    Replies: 11
    Last Post: 31st Aug 2011, 03:19 AM
  2. Need Small help with a Small JS code
    By Netguy in forum Web Development Area
    Replies: 2
    Last Post: 5th Nov 2010, 10:08 AM
  3. Small Bug?
    By DeLeTeD in forum Feedback and Suggestions
    Replies: 8
    Last Post: 9th Oct 2010, 08:16 AM
  4. What's with the small i's?
    By Gempis in forum General Discussion
    Replies: 14
    Last Post: 30th Jun 2010, 06:05 PM
  5. Small GFX Help
    By Cooper in forum Community Cooperative
    Replies: 0
    Last Post: 19th Apr 2010, 09:52 PM

Tags for this Thread

BE SOCIAL