php - Display only values containing specific word in array -
right working on search function json decoded results
the code got looks this:
<?php foreach($soeg_decoded $key => $val){ $value = $val["value"]; $seotitle = $val["seotitle"]; $text = $val["text"]; echo '<tr><td>' . $value . '</td><td>' . $seotitle . '</td><td>' . $text . '</td></tr>'; } ?>
i want show results, contains specific word, stored in variable named $searchtext.
is there functions or commands, can seperate results, , show results contains word stored in $searchtext.
something this:
if($value or $seotitle or $text contains $searchtext){ echo '<tr><td>' . $value . '</td><td>' . $seotitle . '</td><td>' . $text . '</td></tr>'; }
thanks in advance.
you can use substr_count()
<?php foreach($soeg_decoded $key => $val){ $value = $val["value"]; $seotitle = $val["seotitle"]; $text = $val["text"]; if(substr_count($value, $searchtext) || substr_count($seotitle, $searchtext) || substr_count($text, $searchtext)){ echo '<tr><td>' . $value . '</td><td>' . $seotitle . '</td><td>' . $text . '</td></tr>'; } } ?>
read more at:
Comments
Post a Comment