hrisafis Posted December 21, 2007 Share Posted December 21, 2007 Hello to everybody I have a problem with the following pattern When I use this preg_match_all('/<\a href="show_per.phtml\?id=(.*)" class="more_new">(.*)<\/a>/', $result, $shop_url, PREG_SET_ORDER ); everything seems to be fine, but when I send the pattern '/<\a href="show_per.phtml\?id=(.*)" class="more_new">(.*)<\/a>/' through an html form and use this preg_match_all($_POST['pattern'], $result, $shop_url, PREG_SET_ORDER ); nothing seems to work fine. Why is that? Any help will be really appriciated. Thanks a lot. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2007 Share Posted December 21, 2007 what is the string that your running the preg on Quote Link to comment Share on other sites More sharing options...
hrisafis Posted December 21, 2007 Author Share Posted December 21, 2007 what is the string that your running the preg on It is an html page that I get with curl. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2007 Share Posted December 21, 2007 can you post the html it would help me with the regexp Quote Link to comment Share on other sites More sharing options...
hrisafis Posted December 21, 2007 Author Share Posted December 21, 2007 can you post the html it would help me with the regexp The part of the code that interests me is something like this. <tr><td width="60%" class="new_color1" colspan="3"><span class="products">VIA P4M900, CORE 2, VGA, DDR-1, DDR-2, S-ATA1, LAN 10/100, AUDIO-6</span></td> <td class="new_color1" align="right"><b> 41.90 €</b> </td></tr><tr></tr> <tr><td class="new_color1" align="left" width="60%">Για σύγκριση επιλέξτε <input type="Checkbox" name="check1" value="PER.523596" onclick="checkclick('check1')"> <a href="show_per.phtml?id=PER.523596" class="more_new">περισσότερα >></a> </td> <td class="new_color1" colspan="4" align="right"> <a href="basket.phtml?itemid=PER.523596&itemname=&itemprice=41.90&itemquant=1" class="main">Προσθήκη στο καλάθι <img src="clipartfds/basket2.gif" width="20" height="15" alt="Προσθήκη στο καλάθι" border="0"></a> </td></tr> </table> </td></tr> <tr><td> </td></tr> <tr><td><a href="show_per.phtml?id=PER.526673"><img src="images/PER/VSMALL/PER.526673.jpg" alt="" border="0"></a></td><td> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td width="60%" class="new_color" colspan="3"><span class="per"><b> PER.526673 :</b></span> <a href="show_per.phtml?id=PER.526673" class=blue_link><b>GIGABYTE 945GZM-S2</b></a> <br><a href="search_per.phtml?category=%CC%C7%D4%D1%C9%CA%C7+%CA%C1%D1%D4%C1&category2=SOCKET+775" style="text-decoration: none"><font style="bold; font-style: normal; color: #909090;">(ΜΗΤΡΙΚΗ ΚΑΡΤΑ - SOCKET 775)</font></a></td> <td class="new_color" align="right"><span class="small">Τιμή: 38.57 € <br>+ 19% ΦΠΑ: 7.33 € </span></td> </tr> Quote Link to comment Share on other sites More sharing options...
hrisafis Posted December 21, 2007 Author Share Posted December 21, 2007 Sorry I posted the whole code the part you need is actually this: nbsp; <a href="show_per.phtml?id=PER.523596" class="more_new">περισσότερα >> </td> Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2007 Share Posted December 21, 2007 were is the closing tag for the href anyways try this preg_match_all("/<a href=\"show_per.phtml\?id=([^\"]+)\"[^>]+>([^<]+)/",$strText,$arrMatches); print_r($arrMatches); $strText is the actual string from curl Quote Link to comment Share on other sites More sharing options...
hrisafis Posted December 21, 2007 Author Share Posted December 21, 2007 were is the closing tag for the href anyways try this preg_match_all("/<a href=\"show_per.phtml\?id=([^\"]+)\"[^>]+>([^<]+)/",$strText,$arrMatches); print_r($arrMatches); $strText is the actual string from curl Nop not working again, I have to remind you that the pattern was working fine, it was when I sended the pattern as a variable through a form that I was not getting results. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2007 Share Posted December 21, 2007 did you try to each the pattern ? Quote Link to comment Share on other sites More sharing options...
hrisafis Posted December 21, 2007 Author Share Posted December 21, 2007 did you try to each the pattern ? Please explain. What do you mean each the pattern? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2007 Share Posted December 21, 2007 sorry I mean echo it you said you tried to send it through a form maybe extra slashes were added Quote Link to comment Share on other sites More sharing options...
dsaba Posted December 21, 2007 Share Posted December 21, 2007 sorry I mean echo it you said you tried to send it through a form maybe extra slashes were added Yes it could be any number of things, that your magic quotes settings add slashes automatically to post strings is probably a good guess though. A good general rule of thumb in any debugging is to validate/check your inputs/ouputs that you're getting at runtime. This means echoing out stuff. The pattern looks fine: http://nancywalshee03.freehostia.com/regextester/regex_tester.php?seeSaved=gdoa6b3t Here's a function to auto escape slashes if neccesary: <?php function stripslash($str) { if (get_magic_quotes_gpc()) { $str = stripslashes($str); } return $str; } ?> Quote Link to comment Share on other sites More sharing options...
hrisafis Posted December 21, 2007 Author Share Posted December 21, 2007 Seems to be working now, thanks everyone for your help! 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.