preg replace - PHP Complicated preg_match -
it's far reach have been experimenting both preg_match , preg_replace in effort extremely complicated.
i trying take entire paypal button code , extract 13-digit button id number. have used preg_replace of unwanted characters out , expose code 1 line of jumbled mess. unfortunately extracted equals signs too-which assume need extract value= newly generated string.
the second issue face, if can leave equal signs in string have created, there 2 values in paypal button form. now, somehow need ignore first value , grab second id need.
the reason doing because paypal doesn't seem have way copy button id. instead generates code whole form , when click on it, automatically highlights whole form code not allowing highlight small portion want. having make simpler doesn't understand code copy form code, paste in form field , have website automatically grab id number use in script have written.
so far, have this:
<?php $string = ''; $res = preg_replace("/[^a-za-z0-9]/", "", $string); echo $res; ?>
when add paypal form code string @ top - looks this:
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" value="d3dpv3y2wsa4j"> <input type="image" src="https://www.paypalobjects.com/en_us/i/btn/btn_cart_lg.gif" border="0" name="submit" alt="paypal - safer, easier way pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/en_us/i/scr/pixel.gif" width="1" height="1"> </form>
i this: formtargetpaypalactionhttpswwwpaypalcomcgibinwebscrmethodpostinputtypehiddennamecmdvaluesxclickinputtypehiddennamehostedbuttonidvalued3dpv3y2wsa4jinputtypeimagesrchttpswwwpaypalobjectscomenusibtnbtncartlggifborder0namesubmitaltpaypalthesafereasierwaytopayonlineimgaltborder0srchttpswwwpaypalobjectscomenusiscrpixelgifwidth1height1form
and of course, thing need second value: d3dpv3y2wsa4j
i feel little more research , figure out how leave equals signs in have values looking like: value= i'm not sure able skip first value , grab second.
this great learning experience me - not use code love gain more knowledge. reads this, thank time!
the best solution use dom parser library simple dom parser. can do:
preg_match('/name="hosted_button_id"\s*value="(\w+)"/', $string, $match); $button_id = $match[1];
Comments
Post a Comment