papaface Posted August 2, 2008 Share Posted August 2, 2008 Hello, Can anyone help me in getting the value of this html element using PHP? <param name="src" value="http://someurl.com/hello.php"> Any help would be appreciated! Link to comment https://forums.phpfreaks.com/topic/117834-solved-get-value-of-value/ Share on other sites More sharing options...
cooldude832 Posted August 2, 2008 Share Posted August 2, 2008 the problem is you would need a time machine to do that on the same page because php processes prehypertext thus that element doesn't exist when php exist and dies when php comes back alive. PHP can interact with the end user using the common HTTP protocols of GET/POST to pass variables, but again that can only happen on the second page load. there is also the $_SERVER superglobal array (http://us2.php.net/manual/en/reserved.variables.server.php) that contains some useful info Link to comment https://forums.phpfreaks.com/topic/117834-solved-get-value-of-value/#findComment-606074 Share on other sites More sharing options...
papaface Posted August 2, 2008 Author Share Posted August 2, 2008 No. I dont mean like that. I mean how can I get the value of that specific element as a string. like <?php function getAttribute($attrib, $tag){ //get attribute from html tag $re = '/'.$attrib.'=["\']?([^"\' ]*)["\' ]/is'; preg_match($re, $tag, $match); if($match){ return urldecode($match[1]); }else { return false; } } $tag = '<param name="src" value="http://someurl.com/hello.php">'; echo getAttribute("value", $tag); ?> That will get the value of any element in the string, but I want it get the value when the element's name is "src". Link to comment https://forums.phpfreaks.com/topic/117834-solved-get-value-of-value/#findComment-606077 Share on other sites More sharing options...
cooldude832 Posted August 2, 2008 Share Posted August 2, 2008 actually read the file's content not pass data via a protocol I see. you can do this very simply actually <?php function getAttribute($attrib, $tag){ //get attribute from html tag $re = '/'.$attrib.'=["\']?([^"\' ]*)["\' ]/is'; preg_match($re, $tag, $match); if($match){ return urldecode($match[1]); }else { return false; } } $tag = '<param name="src" value="http://someurl.com/hello.php">'; if(stristr($tag, "name=\"src\""){ echo getAttribute("value", $tag); } else{ echo "name does not equal src"; } ?> Link to comment https://forums.phpfreaks.com/topic/117834-solved-get-value-of-value/#findComment-606079 Share on other sites More sharing options...
papaface Posted August 2, 2008 Author Share Posted August 2, 2008 Thanks, works great. Link to comment https://forums.phpfreaks.com/topic/117834-solved-get-value-of-value/#findComment-606082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.