php1492 Posted October 18, 2009 Share Posted October 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/178119-extracting-url-pointer-within-xml-tag/ Share on other sites More sharing options...
salathe Posted October 18, 2009 Share Posted October 18, 2009 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". Quote Link to comment https://forums.phpfreaks.com/topic/178119-extracting-url-pointer-within-xml-tag/#findComment-939144 Share on other sites More sharing options...
php1492 Posted October 18, 2009 Author Share Posted October 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/178119-extracting-url-pointer-within-xml-tag/#findComment-939153 Share on other sites More sharing options...
salathe Posted October 18, 2009 Share Posted October 18, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/178119-extracting-url-pointer-within-xml-tag/#findComment-939181 Share on other sites More sharing options...
php1492 Posted October 18, 2009 Author Share Posted October 18, 2009 That worked perfectly! Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/178119-extracting-url-pointer-within-xml-tag/#findComment-939390 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.