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:

http://php.net/manual/en/function.substr-count.php


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -