11.9. Extracting Links from an HTML File11.9.2. SolutionUse the pc_link_extractor( ) function shown in Example 11-2. Example 11-2. pc_link_extractor( )
For example: $links = pc_link_extractor($page); 11.9.3. DiscussionThe pc_link_extractor( ) function returns an array. Each element of that array is itself a two-element array. The first element is the target of the link, and the second element is the text that is linked. For example:
The regular expression in pc_link_extractor( ) won't work on all links, such as those that are constructed with JavaScript or some hexadecimal escapes, but it should function on the majority of reasonably well-formed HTML. 11.9.4. See AlsoRecipe 13.8 for information on capturing text inside HTML tags; documentation on preg_match_all( ) at http://www.php.net/preg-match-all.
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|