On Wednesday 10 March 2004 19:53, [EMAIL PROTECTED] wrote: > 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>)
The following will only work when the string contains a single link: $doo = "See also PAGE:15:this page:PAGE."; $dah = preg_replace("|(.*)PAGE:(\d+):(.*):PAGE(.*)|U", "$1<a href=\"main.php?id=$2\">$3</a>$4", $doo); echo "$doo<br>$dah"; Season to taste. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* Victory or defeat! */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php