john_bboy7 Posted April 18, 2009 Share Posted April 18, 2009 I have a code which extracts the title name and link of that title. i get the result fine.. but i dont know how to print it respectively. For example here is my code: preg_match_all('#(?<=class="topictitle">)[^<]+#', $r , $matches1); preg_match_all('#(?<=<span class="topictitle"></span><a href=")[^"]+#', $r , $matches2); foreach($matches1[0] as $val1){ foreach($matches2[0] as $val2){ echo $val1 . "<br />\n"; echo $val2 . "<br />\n"; echo "<br>"; } } Now The above code gives me: Match1(a) Match2(a) Match2(b) Match2© Match2(d) Match1(b) Match2(a) Match2(b) Match2© Match2(d) I want it to be like this: Match1(a) Match2(a) Match1(b) Match2(b) Match1© Match2© I hope you got my question. Link to comment https://forums.phpfreaks.com/topic/154622-solved-small-help-with-array/ Share on other sites More sharing options...
The Little Guy Posted April 18, 2009 Share Posted April 18, 2009 let me know what this prints back to you: preg_match_all('#(?<=class="topictitle">)[^<]+#', $r , $matches1); preg_match_all('#(?<=<span class="topictitle"></span><a href=")[^"]+#', $r , $matches2); echo '<pre>';print_r($matches1);echo '</pre>'; echo '<p> </p>'; echo '<pre>';print_r($matches2);echo '</pre>'; Link to comment https://forums.phpfreaks.com/topic/154622-solved-small-help-with-array/#findComment-813290 Share on other sites More sharing options...
john_bboy7 Posted April 19, 2009 Author Share Posted April 19, 2009 let me know what this prints back to you: preg_match_all('#(?<=class="topictitle">)[^<]+#', $r , $matches1); preg_match_all('#(?<=<span class="topictitle"></span><a href=")[^"]+#', $r , $matches2); echo '<pre>';print_r($matches1);echo '</pre>'; echo '<p> </p>'; echo '<pre>';print_r($matches2);echo '</pre>'; It gives me all the list of titles first then all the list of links i.e. 56 title and 56 links.. But i want it to be like title link title link and so on.. i hope u get it.. Is the no such thing in foreach which causes both value to be in for e.g: foreach($matches1[0] as $val1 AND $matches2[0] as $val2){ And then print it... Link to comment https://forums.phpfreaks.com/topic/154622-solved-small-help-with-array/#findComment-813633 Share on other sites More sharing options...
Rithiur Posted April 19, 2009 Share Posted April 19, 2009 A simple for loop would do it for you. For example: $size = count($matches1[0]); for ($i = 0; $i < $size; $i++) { echo $matches1[0][$i] . "<br />\n"; echo $matches2[0][$i] . "<br />\n"; echo "<br />\n"; } Link to comment https://forums.phpfreaks.com/topic/154622-solved-small-help-with-array/#findComment-813639 Share on other sites More sharing options...
john_bboy7 Posted April 19, 2009 Author Share Posted April 19, 2009 A simple for loop would do it for you. For example: $size = count($matches1[0]); for ($i = 0; $i < $size; $i++) { echo $matches1[0][$i] . "<br />\n"; echo $matches2[0][$i] . "<br />\n"; echo "<br />\n"; } Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' @ line ==> $size = count($matches1[0]); Link to comment https://forums.phpfreaks.com/topic/154622-solved-small-help-with-array/#findComment-813647 Share on other sites More sharing options...
Rithiur Posted April 19, 2009 Share Posted April 19, 2009 Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' @ line ==> $size = count($matches1[0]); You are most likely missing a semicolon from the previous line that has code in it Link to comment https://forums.phpfreaks.com/topic/154622-solved-small-help-with-array/#findComment-813650 Share on other sites More sharing options...
john_bboy7 Posted April 19, 2009 Author Share Posted April 19, 2009 Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' @ line ==> $size = count($matches1[0]); You are most likely missing a semicolon from the previous line that has code in it Sorry my bad.. Man u r really genius.. you solved my two topics in 1 minute.. Thankyou very much.. Link to comment https://forums.phpfreaks.com/topic/154622-solved-small-help-with-array/#findComment-813653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.