• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
preg_replace_callback

#1
[eluser]easymind[/eluser]
Hi,

this is not really a codeingiter question, but help is often available here and I am developping in CI Smile

The situation:
I have all kinds of texts inside my database. These texts have hyperlinks in them like:

Code:
<a href="!localfile:3,4">link to file</a>

The second digit (the 4) is the id of a file I have also stored in the databse. These files have tags or names also. So what I want is a search throught the text and a replacement where !localfile:3,4 becomes a real link. What I had in mind was:
Code:
preg_replace("/href=\"!localfile:\d,(\d)/",
             '"href=\"".site_url()."downloadfile/".$this->getfiletagbyid($1)',
             $pagetext);

But ofcourse this is not working since you cannot run methods from objects, only functions. I have looked into preg_replace_callback and also call_user_func, bot cannot get it working.

So I need to replace id's in a text with filetags and I do not want to put all files in an array (or something) first.

Hope somebody can help.

Brt


Messages In This Thread
preg_replace_callback - by El Forum - 12-06-2007, 08:33 AM
preg_replace_callback - by El Forum - 12-06-2007, 08:56 AM
preg_replace_callback - by El Forum - 12-06-2007, 10:49 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.