mraza Posted October 9, 2010 Share Posted October 9, 2010 Hi i wants to add a word before a text but it is not showing property , please can anyone help <?php$a = "Your Tax id is T34Y65 and other text";$a = preg_replace('/T[0-9]{2}Y[0-9]{2}/',"= (\1)",$a);echo $a;?> i wants this Your Tax id is T34Y65 and other text to Your Tax id is = T34Y65 and other text but it gives empty. like "Your Tax id is = and other text" Quote Link to comment https://forums.phpfreaks.com/topic/215497-regex-problem/ Share on other sites More sharing options...
DavidAM Posted October 9, 2010 Share Posted October 9, 2010 In your replacement string you are referencing the first captured string, but you are not capturing any strings in your pattern. You need to put parenthesis around the pattern to be captured and you don't put them around the replacement: preg_replace('/(T[0-9]{2}Y[0-9]{2})/',"= \1",$a); Quote Link to comment https://forums.phpfreaks.com/topic/215497-regex-problem/#findComment-1120582 Share on other sites More sharing options...
mraza Posted October 9, 2010 Author Share Posted October 9, 2010 Thanks solved Quote Link to comment https://forums.phpfreaks.com/topic/215497-regex-problem/#findComment-1120588 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.