axiom007 Posted September 4, 2008 Share Posted September 4, 2008 The company I work for uses a lot of web services to interact with thier ERP. However, instead of returning data, it returns html strings. How could I pull the order number out of this html string <table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td width="100%" align="center" class="pageHeading">Your order has been processed!<br /><br /></td></tr><tr><td width="100%" align="center"><span class="paragraphText">Your Order Number is: 0105318598(BBWO1220556726) </span><br /><br /></td></tr><tr><td width="100%" align="center"><span class="paragraphText">If you have any questions regarding this order, please contact the Fulfillment Department at 555-555-5555.<br /><br />Thank you for shopping with!</span></td></tr></table> Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
drisate Posted September 4, 2008 Share Posted September 4, 2008 put the page into a var then use regex to retrieve the value Quote Link to comment Share on other sites More sharing options...
Hinty Posted September 4, 2008 Share Posted September 4, 2008 Is this what you mean? <? $text = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td width="100%" align="center" class="pageHeading">Your order has been processed!<br /><br /></td></tr><tr><td width="100%" align="center"><span class="paragraphText">Your Order Number is: 0105318598(BBWO1220556726) </span><br /><br /></td></tr><tr><td width="100%" align="center"><span class="paragraphText">If you have any questions regarding this order, please contact the Fulfillment Department at 555-555-5555.<br /><br />Thank you for shopping with!</span></td></tr></table>'; preg_match_all("/<span class=\"paragraphText\">Your Order Number is: (.*) <\/span>/", $text, $matches); print_r($matches[1][0]); ?> This picks the order number from the text. If you want to retrieve it from a URL you can use <? $text = file_get_contents("http://example.com"); //enter url of page here preg_match_all("/<span class=\"paragraphText\">Your Order Number is: (.*) <\/span>/", $text, $matches); print_r($matches[1][0]); ?> If i have misunderstood i apologise Quote Link to comment Share on other sites More sharing options...
axiom007 Posted September 4, 2008 Author Share Posted September 4, 2008 that is real close. I tried the firstcode you suggested and it pulled the order number, but it also pulled the part in parenthesis, the (BBWO....) part. I only need the first part. I am terrible at regex so the suggestion of what I need to add to yours would be appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 4, 2008 Share Posted September 4, 2008 Here: <?php $text = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td width="100%" align="center" class="pageHeading">Your order has been processed!<br /><br /></td></tr><tr><td width="100%" align="center"><span class="paragraphText">Your Order Number is: 0105318598(BBWO1220556726) </span><br /><br /></td></tr><tr><td width="100%" align="center"><span class="paragraphText">If you have any questions regarding this order, please contact the Fulfillment Department at 555-555-5555.<br /><br />Thank you for shopping with!</span></td></tr></table>'; $matched = array(); preg_match('/(?: )(\d+(?=\())/', $text, $matched); print_r($matched); ?> $matched[1] will be your number. Quote Link to comment Share on other sites More sharing options...
Hinty Posted September 4, 2008 Share Posted September 4, 2008 ahh i get you <? $text = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td width="100%" align="center" class="pageHeading">Your order has been processed!<br /><br /></td></tr><tr><td width="100%" align="center"><span class="paragraphText">Your Order Number is: 0105318598(BBWO1220556726) </span><br /><br /></td></tr><tr><td width="100%" align="center"><span class="paragraphText">If you have any questions regarding this order, please contact the Fulfillment Department at 555-555-5555.<br /><br />Thank you for shopping with!</span></td></tr></table>'; preg_match_all("/<span class=\"paragraphText\">Your Order Number is: (.*)(BBWO[^>]*) <\/span>/", $text, $matches); $matches[1][0] = str_replace("(", "", $matches[1][0]); print_r($matches[1][0]); ?> i had to include a string repalce because no matetr what i did there was always a '(' at the end of the string hope thats what you want! Quote Link to comment Share on other sites More sharing options...
Hinty Posted September 4, 2008 Share Posted September 4, 2008 nice DarkWater Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 4, 2008 Share Posted September 4, 2008 Thanks. Use mine, thread starter. For your info, Hinty, I used a positive lookahead for the parenthesis. I could have actually made the regex: <?php $text = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td width="100%" align="center" class="pageHeading">Your order has been processed!<br /><br /></td></tr><tr><td width="100%" align="center"><span class="paragraphText">Your Order Number is: 0105318598(BBWO1220556726) </span><br /><br /></td></tr><tr><td width="100%" align="center"><span class="paragraphText">If you have any questions regarding this order, please contact the Fulfillment Department at 555-555-5555.<br /><br />Thank you for shopping with!</span></td></tr></table>'; $matched = array(); preg_match('/(?<= )(\d+(?=\())/', $text, $matched); print_r($matched); ?> Which would make $matched[0] and $matched[1] equal the number he wants. In fact, use this one, thread starter. Quote Link to comment Share on other sites More sharing options...
axiom007 Posted September 4, 2008 Author Share Posted September 4, 2008 thaank you for all of your help, works beautifully! Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 4, 2008 Share Posted September 4, 2008 No problem. 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.