English 中文(简体)
使用PHP正则表达式从HTML中提取一些文本[重复]
原标题:Extracting some text from HTML using PHP regular expressions [duplicate]
This question already has an answer here:
Closed 12 years ago.

Possible Duplicate:
find and edit comment element of html with php

你好一般来说,正则表达式让我难以理解。我的问题的答案应该很简单,但经过一段时间的挖掘,我仍然不知道答案是什么。如何使用PHP中的preg_match()从HTML摘录中提取“Orange County,CA”?:

<!-- CLTAG GeographicArea=Orange County, CA -->

请注意,此区域中的文本将是可变的,因此正则表达式需要是动态的才能说明这一点。

最佳回答

您可以使用的一个正则表达式是:

$matches = array();
preg_match( /<!-- CLTAG GeographicArea=(.*?) -->/ , $html, $matches);

echo $matches[1];

如果HTML中有多个这样的注释,请使用preg_match_all()

问题回答

正则表达式:

preg_match( #<--(.*)=(.*)--># , $html, $matches);
$matches[1] //contain data




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签