jordan443 Posted April 24, 2013 Share Posted April 24, 2013 (edited) Currently, I have made script that gets a lot of links from another site and puts these links into a form format, where it POSTs the value of the link to another page on my site. That works fine. The problem is that the value of every link is the same. Is there any way to make the value of the <a> tags match the text in between the <a> tags? For example: I want to make this: <a value="">One</a> <a value="">Two</a> <a value="">Purple</a> <a value="">Four</a> <a value="">Puppy</a> Be automatically changed to this: <a value="One">One</a> <a value="Two">Two</a> <a value="Purple">Purple</a> <a value="Four">Four</a> <a value="Puppy">Puppy</a> Any ideas? Edited April 24, 2013 by jordan443 Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 24, 2013 Share Posted April 24, 2013 Try something like this instead: $file_contents = file_get_contents('http://eyemanga.com'); preg_match_all('/<a class="cvr" href="([^"]+)"/', $file_contents, $matches); foreach ($matches[1] as $link) echo '<a href="'.$link.'">'.$link.'</a>'; Quote Link to comment Share on other sites More sharing options...
Q695 Posted April 24, 2013 Share Posted April 24, 2013 You can either do a target, or AngularJS Quote Link to comment Share on other sites More sharing options...
jordan443 Posted April 25, 2013 Author Share Posted April 25, 2013 Try something like this instead: $file_contents = file_get_contents('http://eyemanga.com'); preg_match_all('/<a class="cvr" href="([^"]+)"/', $file_contents, $matches); foreach ($matches[1] as $link) echo '<a href="'.$link.'">'.$link.'</a>'; I tried what you suggested and I'm not sure how to apply it to my current code? Quote Link to comment Share on other sites More sharing options...
davidannis Posted April 25, 2013 Share Posted April 25, 2013 I tried what you suggested and I'm not sure how to apply it to my current code? Perhaps if you posted at least some of the code it would be easier for others to help you figure out how to change it. Quote Link to comment Share on other sites More sharing options...
jordan443 Posted April 25, 2013 Author Share Posted April 25, 2013 (edited) Perhaps if you posted at least some of the code it would be easier for others to help you figure out how to change it. So this is what I have put together so far: <form id="theform" method="POST" action="/description.php"> <input type="hidden" name="manga" value="value"/> </form> <?php $file_contents = file_get_contents('http://eyemanga.com'); $start = strpos($file_contents, '<style>table{margin:0 0 10px 0}'); $end = strpos($file_contents, '</tr> </table> </td> </tr> </table>', $start); $rawcode = substr($file_contents, $start, $end); $code = str_replace('<a class="cvr"', "<a", "$rawcode"); preg_match_all('/<a href="([^"]+)"/', $code, $matches); foreach ($matches[1] as $link) $codetest = str_replace('<a', '<a onclick="document.forms.theform.manga.value=\''.$link.'\';document.forms.theform.submit();return false"', "$code"); echo $codetest; ?> The problem is that now it is posting the same value for every link Edited April 25, 2013 by jordan443 Quote Link to comment Share on other sites More sharing options...
davidannis Posted April 25, 2013 Share Posted April 25, 2013 (edited) When I tried it I got the following result, It looks like the href is correct, just not the onclick. I'll see if I can fix it. <form id="theform" method="POST" action="/description.php"> <input type="hidden" name="manga" value="value"/> </form> <style>table{margin:0 0 10px 0}table.chp{margin:0!important;width:100%}tr,td{padding:0;margin:0}table.chp td.c1{}table.chp td.c2{width:85px}table.chp td.c3{width:40px}table.chp td.c4{width:75px}a.cvr{display:block;width:36px;height:36px;overflow:hidden}</style> <div class="wpm_pag mng_lts_chp"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/medaka-box/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/215;medaka-box_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/medaka-box/" style="font-size:14px"><b>Medaka Box</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/medaka-box/192/">Chapter 192 - END</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/1730;kingdom_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/" style="font-size:14px"><b>Kingdom</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/85/">Chapter 85 - Kyoukai's Dance</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/84/">Chapter 84 - Assassin's Strike</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/83/">Chapter 83 - Shiyuu</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/82/">Chapter 82 - Hundred-Man Commander</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/81/">Chapter 81 - Farewell</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/80/">Chapter 80 - Separation</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kodomo-no-jikan/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/544;kodomo-no-jikan_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kodomo-no-jikan/" style="font-size:14px"><b>Kodomo no Jikan</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kodomo-no-jikan/93/">Chapter 93 - END</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kissxsis/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/464;kissxsis_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kissxsis/" style="font-size:14px"><b>KissxSis</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kissxsis/71/">Chapter 71 - Secret Affection</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/last-inning/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/804;last-inning_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/last-inning/" style="font-size:14px"><b>Last Inning</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/last-inning/152/">Chapter 152 - A Sudden Turn</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/watashi-ni-xx-shinasai/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/440;watashi-ni-xx-shinasai_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/watashi-ni-xx-shinasai/" style="font-size:14px"><b>Watashi ni xx Shinasai!</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/watashi-ni-xx-shinasai/47/">Chapter 47 - Feelings Within The Pin</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/dogs-bullets-carnage/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/dogs-bullets-carnage_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/dogs-bullets-carnage/" style="font-size:14px"><b>Dogs: Bullets & Carnage</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/dogs-bullets-carnage/82/">Chapter 82 - Chapter 82</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/dogs-bullets-carnage/81/">Chapter 81 - Chapter 81</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/dogs-bullets-carnage/80/">Chapter 80 - Chapter 80</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/hungry-joker/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/hungry_1_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/hungry-joker/" style="font-size:14px"><b>Hungry Joker</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/hungry-joker/21/">Chapter 21 - Human vs. God</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/haikyu/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/haikyu_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/haikyu/" style="font-size:14px"><b>Haikyu!!</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/haikyu/58/">Chapter 58 - Chapter 58</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/shinobi-no-kuni/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/shinobi-no-kuni_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/shinobi-no-kuni/" style="font-size:14px"><b>Shinobi no Kuni</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/shinobi-no-kuni/20/">Chapter 20 - Chapter 20</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/city-of-dead-sorcerer/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/city-of-dead-sorcerer_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/city-of-dead-sorcerer/" style="font-size:14px"><b>City of Dead Sorcerer</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/city-of-dead-sorcerer/46/">Chapter 46 - Chapter 46</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/assassination-classroom/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/assassination-classroom_2_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/assassination-classroom/" style="font-size:14px"><b>Assassination Classroom</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/assassination-classroom/40/">Chapter 40 - Nomination Time.</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/i-dont-want-this-kind-of-hero/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/i-dont-want-this-kind-of-hero_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/i-dont-want-this-kind-of-hero/" style="font-size:14px"><b>I Don't Want This Kind of Hero</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/i-dont-want-this-kind-of-hero/9/">Chapter 9 - Chapter 9</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/celestial-clothes/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/celestial-clothes_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/celestial-clothes/" style="font-size:14px"><b>Celestial Clothes</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/celestial-clothes/6/">Chapter 6 - Fate and Wish</a></td> <td class="c2">Apr 24, 2013</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/celestial-clothes/5/">Chapter 5 - Breaking the evil</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/nichijou/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/nichijou_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/nichijou/" style="font-size:14px"><b>Nichijou</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/nichijou/69/">Chapter 69 - Chapter 69</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/again/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/again_1_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/again/" style="font-size:14px"><b>Again!!</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/again/34/">Chapter 34 - Chapter 34</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="1 Edited April 25, 2013 by davidannis Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 25, 2013 Share Posted April 25, 2013 str_replace replaces ALL occurrences, so your loop is just overwriting $codetest with different values every time. You want to do something like this: <form id="theform" method="POST" action="/description.php"> <input type="hidden" name="manga" value="value"/> </form> <?php $file_contents = file_get_contents('http://eyemanga.com'); preg_match_all('/<a href="([^"]+)"/', $file_contents, $matches); foreach ($matches[1] as $link) echo '<a href="" onclick="document.forms.theform.manga.value=\''.$link.'\';document.forms.theform.submit();return false">'.$link.'</a><br/>'; ?> Quote Link to comment Share on other sites More sharing options...
jordan443 Posted April 25, 2013 Author Share Posted April 25, 2013 When I tried it I got the following result, which appears to be correct: <form id="theform" method="POST" action="/description.php"> <input type="hidden" name="manga" value="value"/> </form> <style>table{margin:0 0 10px 0}table.chp{margin:0!important;width:100%}tr,td{padding:0;margin:0}table.chp td.c1{}table.chp td.c2{width:85px}table.chp td.c3{width:40px}table.chp td.c4{width:75px}a.cvr{display:block;width:36px;height:36px;overflow:hidden}</style> <div class="wpm_pag mng_lts_chp"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/medaka-box/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/215;medaka-box_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/medaka-box/" style="font-size:14px"><b>Medaka Box</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/medaka-box/192/">Chapter 192 - END</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/1730;kingdom_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/" style="font-size:14px"><b>Kingdom</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/85/">Chapter 85 - Kyoukai's Dance</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/84/">Chapter 84 - Assassin's Strike</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/83/">Chapter 83 - Shiyuu</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/82/">Chapter 82 - Hundred-Man Commander</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/81/">Chapter 81 - Farewell</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kingdom/80/">Chapter 80 - Separation</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kodomo-no-jikan/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/544;kodomo-no-jikan_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kodomo-no-jikan/" style="font-size:14px"><b>Kodomo no Jikan</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kodomo-no-jikan/93/">Chapter 93 - END</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kissxsis/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/464;kissxsis_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kissxsis/" style="font-size:14px"><b>KissxSis</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/kissxsis/71/">Chapter 71 - Secret Affection</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/last-inning/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/804;last-inning_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/last-inning/" style="font-size:14px"><b>Last Inning</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/last-inning/152/">Chapter 152 - A Sudden Turn</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/watashi-ni-xx-shinasai/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/440;watashi-ni-xx-shinasai_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/watashi-ni-xx-shinasai/" style="font-size:14px"><b>Watashi ni xx Shinasai!</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/watashi-ni-xx-shinasai/47/">Chapter 47 - Feelings Within The Pin</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/dogs-bullets-carnage/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/dogs-bullets-carnage_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/dogs-bullets-carnage/" style="font-size:14px"><b>Dogs: Bullets & Carnage</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/dogs-bullets-carnage/82/">Chapter 82 - Chapter 82</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/dogs-bullets-carnage/81/">Chapter 81 - Chapter 81</a></td> <td class="c2">Today</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/dogs-bullets-carnage/80/">Chapter 80 - Chapter 80</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/hungry-joker/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/hungry_1_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/hungry-joker/" style="font-size:14px"><b>Hungry Joker</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/hungry-joker/21/">Chapter 21 - Human vs. God</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/haikyu/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/haikyu_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/haikyu/" style="font-size:14px"><b>Haikyu!!</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/haikyu/58/">Chapter 58 - Chapter 58</a></td> <td class="c2">Today</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/shinobi-no-kuni/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/shinobi-no-kuni_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/shinobi-no-kuni/" style="font-size:14px"><b>Shinobi no Kuni</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/shinobi-no-kuni/20/">Chapter 20 - Chapter 20</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/city-of-dead-sorcerer/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/city-of-dead-sorcerer_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/city-of-dead-sorcerer/" style="font-size:14px"><b>City of Dead Sorcerer</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/city-of-dead-sorcerer/46/">Chapter 46 - Chapter 46</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/assassination-classroom/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/assassination-classroom_2_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/assassination-classroom/" style="font-size:14px"><b>Assassination Classroom</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/assassination-classroom/40/">Chapter 40 - Nomination Time.</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/i-dont-want-this-kind-of-hero/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/i-dont-want-this-kind-of-hero_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/i-dont-want-this-kind-of-hero/" style="font-size:14px"><b>I Don't Want This Kind of Hero</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/i-dont-want-this-kind-of-hero/9/">Chapter 9 - Chapter 9</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/celestial-clothes/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/celestial-clothes_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/celestial-clothes/" style="font-size:14px"><b>Celestial Clothes</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/celestial-clothes/6/">Chapter 6 - Fate and Wish</a></td> <td class="c2">Apr 24, 2013</td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/celestial-clothes/5/">Chapter 5 - Breaking the evil</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/nichijou/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/nichijou_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/nichijou/" style="font-size:14px"><b>Nichijou</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/nichijou/69/">Chapter 69 - Chapter 69</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td width="40px"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/again/"> <img src="http://eyemanga.com/wp-content/manga/cover/tbn/again_1_36x0.jpg"/> </a> </td> <td> <table class="chp"> <tr> <td colspan="4"> <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/again/" style="font-size:14px"><b>Again!!</b></a> </td> </tr> <tr> <td class="c1"><a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/again/34/">Chapter 34 - Chapter 34</a></td> <td class="c2">Apr 24, 2013</td> </tr> </table> </td> </tr> </table> <hr style="border:dashed #BEBEBE; border-width:1px 0 0; height:0;"> <table width="1 But if you click one of the links, you'll notice that it POSTs the same value for every instance of document.forms.theform.manga.value= For example: <a onclick="document.forms.theform.manga.value='http://eyemanga.com/again/34/';document.forms.theform.submit();return false" href="http://eyemanga.com/assassination-classroom/" style="font-size:14px"><b>Assassination Classroom</b></a> Every manga item in the output has a value of 'http://eyemanga.com/again/34/' (or whatever the first link is) when I want the value to match the link in the href attribute. So I wanted the code above to be: <a onclick="document.forms.theform.manga.value='http://eyemanga.com/assassination-classroom/';document.forms.theform.submit();return false" href="http://eyemanga.com/assassination-classroom/" style="font-size:14px"><b>Assassination Classroom</b></a> Quote Link to comment Share on other sites More sharing options...
jordan443 Posted April 25, 2013 Author Share Posted April 25, 2013 (edited) Lemmin, thats what I tried at first but the output of it only shows the links when I want to keep the styling and text. So is there a way to use a foreach loop with an alternative to str_replace that will replace each document.forms.theform.manga.value='(whatever)' value with the link in each href attribute? Edited April 25, 2013 by jordan443 Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 25, 2013 Share Posted April 25, 2013 What you should be doing is scraping for ONLY the data that you need, then format it however you want to. Especially since the HTML on that web site is horrible. BUT, if you want to do it that way: <form id="theform" method="GET" action="/description.php"> <input type="hidden" name="manga" value="value"/> </form> <?php $file_contents = file_get_contents('http://eyemanga.com'); preg_match_all('/<table width="100%".+?<\/table>\s*<\/td>\s*<\/tr>\s*<\/table>/ims', $file_contents, $matches); $tables = $matches[0]; $html = ''; foreach ($tables as $table) $html .= preg_replace('/(<a[^>]+href="([^"]+)")/', '$1 onclick="document.forms.theform.manga.value=\'$2\';document.forms.theform.submit();return false"', $table); echo $html; ?> Quote Link to comment Share on other sites More sharing options...
Solution davidannis Posted April 25, 2013 Solution Share Posted April 25, 2013 That was challenging because some of the links are substrings of other links, So, I think you need to iterate through and work on one link at a time. I believe that this works: <form id="theform" method="POST" action="/description.php"> <input type="hidden" name="manga" value="value"/> </form> <?php $file_contents = file_get_contents('http://eyemanga.com'); $start = strpos($file_contents, '<style>table{margin:0 0 10px 0}'); $end = strpos($file_contents, '</tr> </table> </td> </tr> </table>', $start); $rawcode = substr($file_contents, $start, $end); $code = str_replace('<a class="cvr"', "<a", "$rawcode"); preg_match_all('/<a href="([^"]+)"/', $code, $matches); foreach ($matches[1] as $link){ $linkpos=strpos($code, $link); $work= substr($code, 0, $linkpos); $code= substr($code,$linkpos+(strlen($link)+1)); $codetest.=$work.$link.'" onclick="document.forms.theform.manga.value=\''.$link.'\';document.forms.theform.submit();return false"'; } echo $codetest; ?> Quote Link to comment 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.