1

I'm working on a script which have to extract all a tags from a URL but not only the value from a tag, I mean all a tag code like this:

<a href="test">Text</a>

I find something with preg_match_all but this only extract the values from href, title, etc, not the entire a tag code. What should I make?

2

2 Answers 2

2

you can use a html parser : A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way!

Sign up to request clarification or add additional context in comments.

5 Comments

i can't extract full path using this library
@dev.bashar with $element->href , you can get full path .
no i can't it's return about_us.php services.php portfolio.php i need the full path with http
some of returns links like ../../services
i found what i am looking for here github.com/aaronclinger/relative-url-helper thank you
0

Use Simplehtmldom library to get data from url

// Include the library
include('simple_html_dom.php');

// Retrieve the DOM from a given URL
$html = file_get_html('http://davidwalsh.name/');

// Find all "A" tags and print their HREFs
foreach($html->find('a') as $e) 
    echo $e->href . '<br>';

// Retrieve all images and print their SRCs
foreach($html->find('img') as $e)
    echo $e->src . '<br>';

1 Comment

i can't extract full path using this library

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.