RE: [PHP] REGEX prob

From: Date: Sun, 18 Feb 2001 16:25:51 +0000
Subject: RE: [PHP] REGEX prob
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-40429@lists.php.net to get a copy of this message
did you check the value *before* writing it to a file? before trying to solve any problem, you have to know where to look.... perhaps the problem lies with the file instead of the regexp. the following code worked great for me: <?php $html='<a href="link.htm?something=value&flag=982420537&PHPSESSID=2c86b460d360b13c3ef08b8a46b9c afc">Lnk</a>'; $html = preg_replace('/&flag=(\d{9})&PHPSESSID=(\w{32})/', append_url(), $html ); print $html; save_url($html); die("Done"); function append_url() { return "&new_url=this"; } function save_url($html) { if ( !($f = fopen('test.txt', 'w')) ) { die("Cannot write file"); } else { fwrite($f, $html); fclose($f); } return 1; } ?> > -----Original Message----- > From: n e t b r a i n [mailto:net-brain@net-brain.net] > Sent: Saturday, February 17, 2001 12:49 > To: php-general@lists.php.net > Subject: [PHP] REGEX prob > > > Hi all, > > I'm trying to match a particular piece of string in a big string using a > regex in order to change it whith another value ... I mean: > > eg: > > $html="<a > href=link.htm?&flag=982420537&PHPSESSID=2c86b460d360b13c3ef08b8a46b9cafc>Lnk > </a>"; > > function change_sess(&$html_code){ > if(eregi("&flag=[0-9]{9}&PHPSESSID=[[:alnum:]]{32}",$html_code)){ > > > str_replace("&flag=[0-9]{9}&PHPSESSID=[[:alnum:]]{32}","<?=append_url();?>", > $html_code); > } > } > > change_sess($html); > ... > $fp=fopen($my_file,"w"); > fwrite($fp,$html); > ... > > But open the $my_file, the changes are not applied ... (I mean: there's > always the original string --> > &flag=982420537&PHPSESSID=2c86b460d360b13c3ef08b8a46b9cafc) > > Anyone could help me, please? > > many thanks in advance > max > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#40429) next »