katerina Posted September 4, 2008 Share Posted September 4, 2008 I want to match all tables from a page and then to print it on screen like that : Table 1 --> <table border="" width="" align=""> Table 2 --> <table . . . . . . . .> Table 3 --> <table . . . . . . . . .> Could someone help me ??? I need the same for area element Quote Link to comment https://forums.phpfreaks.com/topic/122770-match-tables-and-areas/ Share on other sites More sharing options...
DarkWater Posted September 4, 2008 Share Posted September 4, 2008 Uhh, what? So me an example page and the desired output. Quote Link to comment https://forums.phpfreaks.com/topic/122770-match-tables-and-areas/#findComment-633944 Share on other sites More sharing options...
effigy Posted September 4, 2008 Share Posted September 4, 2008 Here's a start: preg_match_all('%<(table|area)[^>]*>.*?</\1>%', $data, $matches); print_r($matches); Quote Link to comment https://forums.phpfreaks.com/topic/122770-match-tables-and-areas/#findComment-633971 Share on other sites More sharing options...
katerina Posted September 4, 2008 Author Share Posted September 4, 2008 I need it in diferrent regular expressions one for table and another for area. I try <html> <body> <?php $url="http://www.microsoft.com"; $file = file_get_contents($url); preg_match_all('%<table[^>]*>.*?</\1>%', $file, $matches); print_r($matches); ?> </body> </html> But I take error : Warning: preg_match_all() [function.preg-match-all]: Compilation failed: reference to non-existent subpattern at offset 20 in C:\wamp\www\php examples\example.php on line 7 And last question, I have to do this for every element on a html code. Is there an easier way ?? Something like switch($elem) { case 'a' : . . . case 'area' : ... case 'table' : ... case 'td' : ... } Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/122770-match-tables-and-areas/#findComment-634017 Share on other sites More sharing options...
katerina Posted September 5, 2008 Author Share Posted September 5, 2008 please somebody ?? Quote Link to comment https://forums.phpfreaks.com/topic/122770-match-tables-and-areas/#findComment-634520 Share on other sites More sharing options...
effigy Posted September 5, 2008 Share Posted September 5, 2008 You need the parentheses. Look at my example again. What are you trying to do for every element? Quote Link to comment https://forums.phpfreaks.com/topic/122770-match-tables-and-areas/#findComment-634580 Share on other sites More sharing options...
katerina Posted September 6, 2008 Author Share Posted September 6, 2008 I ask an url from an user. I read the source code of the page. And I want to insert all elements in database so as to check if for example <img...> element has alt attribute. Do you know how can I do it. It's true difficult for me! Quote Link to comment https://forums.phpfreaks.com/topic/122770-match-tables-and-areas/#findComment-635234 Share on other sites More sharing options...
effigy Posted September 8, 2008 Share Posted September 8, 2008 Why are you using a regular expression if you want to insert all of the elements? Why can't you simply use $file from your example? Do you want to break the data apart by pairs of tags? What if these contain other tags? Quote Link to comment https://forums.phpfreaks.com/topic/122770-match-tables-and-areas/#findComment-636563 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.