marcus Posted July 18, 2007 Share Posted July 18, 2007 I'm trying to make it so: [profile=username] replaces with username(username) username() is a function I have that links the "username" to that profile $string = "[profile=marcus;]"; echo "Before: $string<br>\n"; echo "After: "; echo preg_replace("[profile=(.*?);]",username("\\1"),$string); I get: Before: [profile=marcus;] After: [marcus] The after statement is producing a link to that profile with an image. The image identifies the user's level, the link is correct. How would I remove the brackets on the start and the end of "[marcus]" ? Link to comment https://forums.phpfreaks.com/topic/60625-preg_replace-help/ Share on other sites More sharing options...
effigy Posted July 18, 2007 Share Posted July 18, 2007 I'm confused at what you're trying to achieve on a step-by-step basis. Are you saying everything works fine, except the end result needs to remove the braces? Or are the braces the result of something not being processed correctly? Link to comment https://forums.phpfreaks.com/topic/60625-preg_replace-help/#findComment-301608 Share on other sites More sharing options...
marcus Posted July 19, 2007 Author Share Posted July 19, 2007 I don't want the braces, and the variable inside the username function is not passing correctly. Username function does: [puts image on administrative level][link to profile] I'm getting: [frozenpic][link to profile] Therefore the username isn't in existence. Link to comment https://forums.phpfreaks.com/topic/60625-preg_replace-help/#findComment-301900 Share on other sites More sharing options...
clearstatcache Posted July 19, 2007 Share Posted July 19, 2007 try ds.... preg_replace("/profile=(.*?);/",username("\\1"),$string); Link to comment https://forums.phpfreaks.com/topic/60625-preg_replace-help/#findComment-301901 Share on other sites More sharing options...
marcus Posted July 19, 2007 Author Share Posted July 19, 2007 I'm still getting the wrong image. I'm trying to get image "6", but I keep getting "4" I also believe that the variable is NOT passing threw the username function. I've tried returning the username value inside the function but it's blank. Link to comment https://forums.phpfreaks.com/topic/60625-preg_replace-help/#findComment-301933 Share on other sites More sharing options...
effigy Posted July 19, 2007 Share Posted July 19, 2007 You have two problems: 1. PREG requires delimiters. 2. [ and ] are metacharacters. The [ and ] around your pattern are being considered delimiters and therefore not actually matching a pair of braces. You need to add a delimiter, then escape the braces in order to match them: /\[profile=(.*?);\]/ Link to comment https://forums.phpfreaks.com/topic/60625-preg_replace-help/#findComment-302328 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.