[英]How to find text in webpage through PHP?
I have a pure text file without any HTML formatting. 我有一个纯文本文件,没有任何HTML格式。 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?
我可以这样做吗?
so means: if its: "word1":"i like stackoverflow", next thing
意思是:如果它是:
"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. 我想找到以反逗号分隔的
word1
,然后我想要整个短语, i like stackoverflow
没有反逗号的i like stackoverflow
。 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. 在PHP中,您可以使用诸如
preg_match
类的功能来执行此操作。
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
. 匹配结果将放置在
$match_array
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.