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
https://forums.phpfreaks.com/topic/216585-preg_replace-question/
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]);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.