开发者

How to find text in webpage through PHP?

I have a pure text file without any HTML formatting. I want to search for a word in it? how should i do that? and I also want the next words before a comma. can i do that to?

s开发者_如何学编程o means: if its: "word1":"i like stackoverflow", next thing

i want to find word1 which is in inverted commas and then i want the whole phrase i like stackoverflow without the inverted commas. and it should stop at that point.

is there any way to do that?

thanks...


Use a regular expression. In PHP, you can use a function like preg_match to do this.

For the pattern you described, your regular expression code could be something like:

$match_array = array();
$string_to_match = // load the string from a file and put it in this variable

preg_match('/"([A-Za-z0-9\s]+?)":"([A-Za-z0-9\s]+?)"/', $string_to_match, $match_array);

The results of the match will then be placed in $match_array.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜