I have a problem separting a text string with the preg_split function If somebody could help, it would be greatly appreciated. --------- The problem I have is that my code, so far, does the job, except it recognises ALL ":" and not only those following "PAGE". This should be fairly easy to solve? --------- What I want to do:
As part of a php-controlled content management system, this code has the purpose to link to other page within the same website. Example: "See also this page." When editing content, the administrator should be able to perform this link by editing the string above as: "See also PAGE:15:this page:PAGE.", so containing: PAGE: (opening tag, to be found by php code to insert a <a href...) 15: number of the corresponding page :PAGE (end tag to be replaced by </a>) My code: # -- loop through string until all PAGE requests are processed while(ereg('PAGE:',$string)) { # -- filter text string to separate to make $id_id available $nummer=preg_split("(PAGE|:|PAGE)", $string, -1,PREG_SPLIT_DELIM_CAPTURE); # -- recall $id_id from the resulting array $id_id=$nummer[2]; # -- replace opening tag, so next loop will no longer see the link $string=preg_replace("(PAGE:)","<a href=main.php?id=$id_id>",$string, 1); # -- replace end tag $string=preg_replace("(:PAGE)","</a>",$string, 1); # -- delete visible $id_id because it is still visible in the string $string=preg_replace("($id_id:)", "", $string, 1); } with example $string="Here comes the link: PAGE:15:click here:PAGE" this should, but doesn't produce the result "Here comes the link: <a href=page.php?id=15>click here</a>" ----- kind regards, Jan