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:[EMAIL PROTECTED]]
> Sent: Saturday, February 17, 2001 12:49
> To: [EMAIL PROTECTED]
> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to