Hello i want to extract links
<a href="/portal/clients/show/entityId/2121" >
and i want a regex which givs me /portal/clients/show/entityId/2121
the number at last 2121 is in other links different
any idea?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Paring links from HTML can be done using am HTML parser.
When you have all links, simple get the index of the last forward slash, and you have your number. No regex needed.
Simple PHP HTML Dom Parser example:
This is my solution:
I recommend to avoid using xml-based parsers, because you will not always know, whether the document/website has been well formed.
Best regards
When "parsing" html I mostly rely on PHPQuery: http://code.google.com/p/phpquery/ rather then regex.
Regex for parsing links is something like this:
Given how horrible that is, I would recommend using Simple HTML Dom for getting the links at least. You could then check links using some very basic regex on the link href.
Don't use regular expressions for proccessing xml/html. This can be done very easily using the builtin dom parser: