Graxeon Posted February 22, 2009 Share Posted February 22, 2009 "content.php?a=uhh&?b=umm" outputs: <?xml version="1.0" encoding="UTF-8"?> <user type="cool" thepage="http%3A%2F%2Fgoogle.com" /> How can I grab the contents of "thepage" via PHP? Btw: that is the entire output of "content.php?a=uhh&?b=umm" Quote Link to comment https://forums.phpfreaks.com/topic/146405-solved-grab-contents-in-this-file/ Share on other sites More sharing options...
genericnumber1 Posted February 22, 2009 Share Posted February 22, 2009 you could use simplexml, domxml, or even preg_match in combination with file_get_contents. Quote Link to comment https://forums.phpfreaks.com/topic/146405-solved-grab-contents-in-this-file/#findComment-768689 Share on other sites More sharing options...
Graxeon Posted February 22, 2009 Author Share Posted February 22, 2009 Well I tried this but it didn't work <?php $allowed_url = array("umm", //test start "blankspothere"); $passed_url = $_GET['url']; foreach ($allowed_url as $allowed) { if(stristr($allowed, $passed_url) !== false) { $url='http://www.domain.com/content.php?a=uhh&?b='.$allowed; $string = file_get_contents($url); $sxml = new SimpleXmlElement($string); $node = $sxml->user[0]->attributes()->thepage; header('Location: '.$node); exit; } } header("Location: http://www.google.com/"); ?> I got "Fatal error: Call to a member function attributes() on a non-object on line 13" Quote Link to comment https://forums.phpfreaks.com/topic/146405-solved-grab-contents-in-this-file/#findComment-768694 Share on other sites More sharing options...
Graxeon Posted February 23, 2009 Author Share Posted February 23, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/146405-solved-grab-contents-in-this-file/#findComment-769029 Share on other sites More sharing options...
Graxeon Posted February 23, 2009 Author Share Posted February 23, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/146405-solved-grab-contents-in-this-file/#findComment-769408 Share on other sites More sharing options...
premiso Posted February 23, 2009 Share Posted February 23, 2009 Well you would need to look more into the SimpleXML setup, I do not htink you are using it wrong, hence the error. For a preg_match function to do this, this would work. <?php $string = '<user type="cool" thepage="http%3A%2F%2Fgoogle.com" />'; preg_match("~thepage=\"(.+?)\"~si", $string, $matches); echo urldecode($matches[1]); ?> As far as which is better, I do not know. I have a hunch that the preg_match is quicker due to it does not have to create an object of all the xml elements since you simple want a static element etc. Quote Link to comment https://forums.phpfreaks.com/topic/146405-solved-grab-contents-in-this-file/#findComment-769415 Share on other sites More sharing options...
Graxeon Posted February 23, 2009 Author Share Posted February 23, 2009 Cool, the one you made works perfectly. However...the XML file thing is on a separate file. I can't seem to get this to work, could you help me out? : <?php $allowed_url = array("umm", //test start "blankspothere"); $passed_url = $_GET['url']; foreach ($allowed_url as $allowed) { if(stristr($allowed, $passed_url) !== false) { $string = 'http://www.domain.com/content.php?a=uhh&?b='.$allowed; preg_match("~thepage=\"(.+?)\"~si", $string, $matches); header('Location: '.urldecode($matches[1])); exit; } } header("Location: http://www.google.com/"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/146405-solved-grab-contents-in-this-file/#findComment-769494 Share on other sites More sharing options...
premiso Posted February 23, 2009 Share Posted February 23, 2009 foreach ($allowed_url as $allowed) { if(stristr($allowed, $passed_url) !== false) { $string = file_get_contents('http://www.domain.com/content.php?a=uhh&?b='.$allowed); preg_match("~thepage=\"(.+?)\"~si", $string, $matches); header('Location: '.urldecode($matches[1])); exit; } } Quote Link to comment https://forums.phpfreaks.com/topic/146405-solved-grab-contents-in-this-file/#findComment-769500 Share on other sites More sharing options...
Graxeon Posted February 23, 2009 Author Share Posted February 23, 2009 Oh duh...need to load the content first xD. Ty, it works . Quote Link to comment https://forums.phpfreaks.com/topic/146405-solved-grab-contents-in-this-file/#findComment-769553 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.