PHP DOM parser function

已取消 已发布的 7 年前 货到付款
已取消 货到付款

I need a PHP function which can parse HTML string, search for specific selector path, and return the content of all matched elements. The function will be called parse() and will accept two arguments, as defined: function parse(&$html, $selector). Return value will be array of found code blocks.

The $html parameter will be a complete webpage HTML string. Remember it may be not-perfectly-valid HTML.

The $selector parameter will be a string of space-separated selectors which create full path to one or more subsections of the $html string. For example, $selector can be as simple as "#myelement", which matches everything inside <tag id="myelement">..</tag>

Similarly the selector can be as simple as ".className", which will match all tags with className in "class" attribute, so even <div class="otherClassName className">...</div>

Also the $selector can be more complicated expression, like "[url removed, login to view] [url removed, login to view]"

The above mentioned example selector will match the first and third block in this HTML:

<div class="className1 className2 classNameX"><span class=cls>xxx</span></div>

<div class="className2 className1 classNameX"><span>yyy</span></div>

<div class="classNameX className2 className1"><span class=cls>z<b>z</b>z</span></div>

Return value will be an array with all the subsections of the $html string as matched by the $selector. Pure HTML returned, no objects. So for our example example, with the above mentioned selector and html code, return value will be this array: ["xxx", "z<b>z</b>z"]

You are not allowed to use any external PHP libraries, only use PHP's native functions.

HTML5 PHP

项目ID: #11509192

关于项目

6个方案 远程项目 活跃的7 年前

有6名威客正在参与此工作的竞标,均价$30/小时

Sonicoders

I have 6 years experience as web developer I can provide you the solution we can discuss more details over chat.

$25USD 在1天里
(0条评论)
0.0
Anthony773

hello, I am a php programmer, I have wirtten a similar parser using the library SimpleHtmlDomparser, that recursively parses a series of webpages, depending on the arguments passed to it. Well, using pure php functions 更多

$27USD 在1天里
(0条评论)
0.0
richardalozada

Hi I would like to help make this project I am an expert in this field

$30USD 在1天里
(0条评论)
0.0