html - How to display a specific word in php? -
i need display specific string php, example:
<?php $text = "the grass green" echo $text; ?>
the output the grass green
, how display grass
instead of the grass green
?
if specified word known beforehand, trick:
$word = 'green'; // know keyword $text = "the grass green" // phrase $a = explode(" ", $text); // create array of words in $text foreach ($a $b) // loop through array { if ($b==$word) // if match found, echo { echo $b; break; } }
if on other hand, word in specified position, you:
$wordposition = 2; // know keyword place in phrase $text = "the grass green" // phrase $a = explode(" ", $text); // create array of words in $text echo $a[$wordposition]; // echo specified word, position
Comments
Post a Comment