andre3 Posted June 16, 2009 Share Posted June 16, 2009 Hey guys i want to know if its possible to get the index that's in: id <div class="center" id="index"/> so if i echo $id; it would print out: index i tried using pregmatch all, but it cuts out ever html tag from the page lol thanks! Link to comment https://forums.phpfreaks.com/topic/162325-is-it-possible-to-get-the-value-of/ Share on other sites More sharing options...
ohdang888 Posted June 16, 2009 Share Posted June 16, 2009 i tried using pregmatch all, but it cuts out ever html tag from the page saying that makes it seem as though you are doign one of two things: 1)using javascript 2) using curl or file_get_contents to grab the html of a page... seeing as though you posted this in php, i'll guess you're using #2 you're gonna need to isolate that particular tag you want...assuming the content is mostly the same every time, see what is right before and after that tag, and use another preg_match and store the whole html tag in the var $tag Link to comment https://forums.phpfreaks.com/topic/162325-is-it-possible-to-get-the-value-of/#findComment-856783 Share on other sites More sharing options...
andre3 Posted June 16, 2009 Author Share Posted June 16, 2009 this is what i use: and it still not working accurate, if i put the content in a variable an pass it through preg match to get the value in between ='class1' , example: $val = "the class i want to use is <my class='class1'>"; $result = preg_match_all('%<div[^>]*[\s]class=[\'"]([^\'"]*)[\'"][^>]*>%i', $val, $matches); $result = $matches[1][0]; echo "<div class='$result'>"; if will work like that, but if i remove this: <my class='class1'> from the string then preg match wont return 'the class i want to use is' and if i add any other tags for example: <br/> etc to the string it wont pass them. Link to comment https://forums.phpfreaks.com/topic/162325-is-it-possible-to-get-the-value-of/#findComment-856797 Share on other sites More sharing options...
andre3 Posted June 16, 2009 Author Share Posted June 16, 2009 i figured it out guys, if the preg match didnt find a pattern i should have returned the string Link to comment https://forums.phpfreaks.com/topic/162325-is-it-possible-to-get-the-value-of/#findComment-856809 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.