php check if variable contains a string

seopti
seopti used Ask the Experts™
on
The code below works fine. I would like to add an additional if statement so
if(sizeof($listing['images']) > 0)

AND if

$listing['images']   contains the string   "ecarlist"

the following image should not be loaded:
src="'.$listing['images'][0]['220'].'"
<?php
				if(sizeof($listing['images']) > 0) {
					echo '';
						echo '<div><a rel="'.$listing['id'].'" title="'.$listing['title'].'" href="'.$listing['images'][0]['org'].'"><img style="vertical-align: top;" src="'.$listing['images'][0]['220'].'" /></a></div>';
					$photo_count = sizeof($listing['images']);
					for($x = 1; $x < $photo_count; $x++) {
						if($photo_count > 1) {
						
						echo '<div style="float: left; margin-left: 12px;margin-top:3px;"><a rel="'.$listing['id'].'" title="'.$listing['title'].'" href="'.$listing['images'][$x]['org'].'" target="_blank"><span class="pictureFrame"><span class="image"><img src="'.$listing['images'][$x]['90'].'" title="'.$listing['title'].'" /></span><span class="overlay"></span></span></a></div>';
					
						echo ($x/2 == 0 && $x != $photo_count) ? '<div class="clear></div>' : '';					}
					
					}
					echo '';
				}

				

				?>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
$listing['images']$listing['images']
if( (sizeof($listing['images']) > 0) && preg_match("/ecarlist/", $listing['images']))

Open in new window

Web Expert
Commented:
use below:
if(strpos('ecarlis',$listing['image'])>0)
hope this helps.
Full code:

<?php
				if(sizeof($listing['images']) > 0) {
					echo '';
						echo '<div><a rel="'.$listing['id'].'" title="'.$listing['title'].'" href="'.$listing['images'][0]['org'].'">'. (preg_match("/ecarlist/", $listing['images'])?'<img style="vertical-align: top;" src="'.$listing['images'][0]['220'].'" />':'') . '</a></div>';
					$photo_count = sizeof($listing['images']);
					for($x = 1; $x < $photo_count; $x++) {
						if($photo_count > 1) {
						
						echo '<div style="float: left; margin-left: 12px;margin-top:3px;"><a rel="'.$listing['id'].'" title="'.$listing['title'].'" href="'.$listing['images'][$x]['org'].'" target="_blank"><span class="pictureFrame"><span class="image"><img src="'.$listing['images'][$x]['90'].'" title="'.$listing['title'].'" /></span><span class="overlay"></span></span></a></div>';
					
						echo ($x/2 == 0 && $x != $photo_count) ? '<div class="clear></div>' : '';					}
					
					}
					echo '';
				}

				

?>

Open in new window

Author

Commented:
Thanks but the code does not work:

PHP Parse error:  syntax error, unexpected T_BOOLEAN_AND
Well .. I missed parenthesis around..

<?php
				if(sizeof($listing['images']) > 0) {
					echo '';
						echo '<div><a rel="'.$listing['id'].'" title="'.$listing['title'].'" href="'.$listing['images'][0]['org'].'">'. (preg_match("/ecarlist/", $listing['images'])?('<img style="vertical-align: top;" src="'.$listing['images'][0]['220'].'" />'):'') . '</a></div>';
					$photo_count = sizeof($listing['images']);
					for($x = 1; $x < $photo_count; $x++) {
						if($photo_count > 1) {
						
						echo '<div style="float: left; margin-left: 12px;margin-top:3px;"><a rel="'.$listing['id'].'" title="'.$listing['title'].'" href="'.$listing['images'][$x]['org'].'" target="_blank"><span class="pictureFrame"><span class="image"><img src="'.$listing['images'][$x]['90'].'" title="'.$listing['title'].'" /></span><span class="overlay"></span></span></a></div>';
					
						echo ($x/2 == 0 && $x != $photo_count) ? '<div class="clear></div>' : '';					}
					
					}
					echo '';
				}

				

?>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial