Jump to content

Preg_replace question


Gady Laga

Recommended Posts

Hi there!

 

I'm trying to use preg_replace to include/get content a php file with dynamic variable

 

$txt = "Bla bla bla bla bla [gls]12[/gls] bla bla bla";
$txt = preg_replace("#\[gls\](.*?)\[/gls\]#si",file_get_contents('shipping.php?id=\\1'),$txt);

 

..and it doesn't work. I can not get ID. When I do like that

$txt = preg_replace("#\[gls\](.*?)\[/gls\]#si","My Id is - \\1"),$txt);

 

i see it, but not when I'm using file_get_contents function.

 

Thanks in advance for help.

 

Link to comment
Share on other sites

So it should be:

 


$txt = "Bla bla bla bla bla [gls]12[/gls] bla bla bla";
$txt = preg_replace("#/.*\[gls\]([\d]*)\[\/gls\].*/#si",file_get_contents('shipping_cost_u.php?id=\\1'),$xt);

 

or else? (doesn't work for me)

 

Sorry but I'm not an expert in php ;)

Link to comment
Share on other sites

What are you trying to do?

 

I don't think you're using preg_replace properly.

 

Is this what you want?

$txt = "Bla bla bla bla bla [gls]12[/gls] bla bla bla";
$txt = preg_match("/.*\[gls\]([\d]*)\[\/gls\].*/",$txt, $matches);

$content = file_get_contents('shipping_cost_u.php?id=' . $matches[1]);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.