Gady Laga Posted October 22, 2010 Share Posted October 22, 2010 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 More sharing options...
schilly Posted October 22, 2010 Share Posted October 22, 2010 This pattern worked for me when I tested: /.*\[gls\]([\d]*)\[\/gls\].*/ Remember you need to escape [, ], and / Link to comment https://forums.phpfreaks.com/topic/216585-preg_replace-question/#findComment-1125330 Share on other sites More sharing options...
Gady Laga Posted October 22, 2010 Author Share Posted October 22, 2010 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 https://forums.phpfreaks.com/topic/216585-preg_replace-question/#findComment-1125340 Share on other sites More sharing options...
schilly Posted October 22, 2010 Share Posted October 22, 2010 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 https://forums.phpfreaks.com/topic/216585-preg_replace-question/#findComment-1125380 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.