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

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -