tags:

views:

88

answers:

5

I am writing a php function for wordpress that is executed through an XML feed. Therefore we are excepting a feed and then based on the nodes placing those in our website. What I need help with is we have a bunch of different images of credentials (i.e BBB, chamber of commerce etc) What I need therefore is when there is a link to a BBB then it should display a picture, if not then it should be blank. The problem I am running into is because the BBB links will be random based on different businesses. Any help would be greatly appreciated. Thanks.

If URL "pic" else "no pic"

+1  A: 

Do you mean this? Otherwise please explain your problem better.

if (!empty($url)) {
    echo '<img src="' .$url. '" />';
}
else {
    echo ' ';
}

Check here when empty returns false (and therefore !empty is true) and really consider if this fits your needs.

Felix Kling
Yeah, are we missing something? Is the OP really asking for how to do an if/else structure?
ceejayoz
I think this is what will help me out - I was missing the "!empty" - thank you for your help
Ben
A: 

Maybe I'm missing something, but wouldn't this do?

if($license1) { print "<img src=\"/path/to/bbb.logo\" alt=\"BBB Logo\" />"; }
ceejayoz
A: 

A method would be creating an array like $feeds = array("pic","xml"); then testing if its in array like

if in_array($url,$feeds)
// your code;

or the second method would be creating an temp var like $tmp = $url =="pic" ? "pic" : "nopic"; or to set just an boolean $tmp = $url =="pic" ? TRUE : FALSE;

then you can test it like this

if($url) // if its == "pic" it would return true otherwise false
 //make your url 
streetparade
A: 

Thank you for all your help - I am sort of new with php + XML, but the "!empty" function is what I was looking for. Thanks

Ben
1. You should not write this as an answer. 2. If this is really what you mere missing, ceejayoz's answer is basically the same. 3. Mark an answer (not yours) as accepted. 4. You're welcome ;)
Felix Kling
A: 

Also a shorthand way is to do

But when the given var is an array I think you need to use is_array(), or if it's a class objec,t use is_object() to verify that it has content.

jeffkee