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. Quote Link to comment 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 / Quote Link to comment 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 Quote Link to comment 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]); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.