Jump to content

Recommended Posts

Hi.

 

I'm trying to extract text between two quotation marks in XML.  For example, I want to extract:

 

<a href="www.thisisanexample.com">Click here</a>.  I want to extract www.thisisanexample.com.  But the data I want to extract does not necessarily have to be <a href> link.  It could be <car>, etc...

 

So far I have tried using simpleXML and regex but I seem to be at a dead end. Simplexml I was able to extract the data between tags, which is useful, but I want data that's inside the tags themselves.

 

Any insight would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/178119-extracting-url-pointer-within-xml-tag/
Share on other sites

Give a more specific example of the XML that you want to work with, and what you want to get out of it. SimpleXML can access attribute values (href is an attribute, www... its value) just as easily as "the data between tags".

Here's what I want to do.  I have an author variable that is stored.  For example, "Smith".  Then, that variable is passed to this link: http://dblp.uni-trier.de/search/author?xauthor=smith

 

As you can see there is a list of authors with author tags.  I want to exact the data after author urlpt and before the second >.  So for the first author <author urlpt="a/Abernathy:Frances_Smith">Frances Smith Abernathy</author>.  I want to extract a/Abernathy:Frances_Smith and store that in a variable.

With SimpleXML, one can access attributes using array notation. See this quick example:

 

$xml = new SimpleXMLElement('http://dblp.uni-trier.de/search/author?xauthor=smith', NULL, TRUE);

// Get first author's URL pointer
$urlpt = (string) $xml->author['urlpt'];
echo $urlpt;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.