开发者

Search for text in output and use whatever is behind the text

I was wondering how I could search fo开发者_如何学Gor certain text (ie: description), and use all that's behind that text as a variable (all that is on the same line) in PHP. This needs to be read from an external location, a PHP file that must be ran (the PHP file reads content from a MySQL database and outputs this as a sort of index)

Any help would be appreciated.

Edit to clarify:

Sample input:

Lorum ipsum dolor

Sample output:

dolor


Do you mean that given this string:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

$wordToFind = "cupidatat";

$allTextBehindWordToFind = substr($str, strpos($str, $wordToFind));

echo $allTextBehindWordToFind; 
// outputs: 'cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';

Or:

$allTextBehindWordToFind = substr($str, strpos($str, $wordToFind) + strlen($wordToFind));

echo $allTextBehindWordToFind; 
// outputs: ' non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';


Alternatively, you could do this:

$tail = array_pop(explode($needle, $string, 2));

But be sure to check $tail against the original string. If $needle wasn't found in $string, $tail will be $string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜