Discussion: ereg_replace problem
Afficher un message
Vieux 20/06/2008, 11h08   #2
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: ereg_replace problem

Hugh Oxford wrote:
> I have a string that has been saved in a database from a textarea form
> field.
>
> e.g.
>
> $text = "Dear %name
>
> The date is %date
>
> yours,
>
> %user"
>
> I wish to parse the string replacing every word beginning with % with a
> variable $name, $date etc.
>
> However, whenever I use ereg_replace, it just finds the beginning of the
> whole string, rather than individual words.. eg
>
> ereg_replace('^', 'foo', $text);
>
> returns "fooDear %name ...".


What do _you_ think '^' means?
Also, don't use ereg_*, switch to preg_*

$string = preg_replace('/%([a-z]+)/sie','[you asked for $1]',$string);
--
Rik Wasmus
....moving deadlines for your pleasure.
  Réponse avec citation
 
Page generated in 0,06965 seconds with 9 queries