ibinod Posted August 23, 2009 Share Posted August 23, 2009 Can anyone help me pls i can't get this working $str = '<p>The reality TV’s most hated man has some harsh words for Oscar-winning actress <a href="http://www.mysite.com/name/Angelina_Jolie">Angelina Jolie</a>'; echo preg_replace('/http:\/\/www.mysite.com\/name\/(.*?)\//i',strtolower('\\1'),$str); how can i modify this so the strtolower will work and only the last part string will be lowercased like Angelina_Jolie to angelina_jolie Thanx. Quote Link to comment https://forums.phpfreaks.com/topic/171482-strtolower-not-working-inside-preg_replace/ Share on other sites More sharing options...
.josh Posted August 23, 2009 Share Posted August 23, 2009 why not just strtolower it in the first place, before the preg_replace? But anyways, if you insist, you need to use the x modifier and wrap the strtolower in quotes. Quote Link to comment https://forums.phpfreaks.com/topic/171482-strtolower-not-working-inside-preg_replace/#findComment-904289 Share on other sites More sharing options...
ibinod Posted August 23, 2009 Author Share Posted August 23, 2009 if i use strtolower before preg_replace everything inside $str will be lowercased and i don't want that i just want the url last word to be lowercased and cud you please provde me a sampe code or something i tried various thing but it's not working Quote Link to comment https://forums.phpfreaks.com/topic/171482-strtolower-not-working-inside-preg_replace/#findComment-904298 Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 Just like Crayon Violent said.... Except I think it might need to be the e modifier. Quote Link to comment https://forums.phpfreaks.com/topic/171482-strtolower-not-working-inside-preg_replace/#findComment-904315 Share on other sites More sharing options...
Daniel0 Posted August 23, 2009 Share Posted August 23, 2009 and cud you please provde me a sampe code or something i tried various thing but it's not working It'll be like this: echo preg_replace('/http:\/\/www.mysite.com\/name\/(.*?)\//ie',"strtolower('\\1')",$str); The e modifier tells it that the thing in the second argument should be evaluated as PHP code. Quote Link to comment https://forums.phpfreaks.com/topic/171482-strtolower-not-working-inside-preg_replace/#findComment-904319 Share on other sites More sharing options...
ibinod Posted August 23, 2009 Author Share Posted August 23, 2009 and cud you please provde me a sampe code or something i tried various thing but it's not working It'll be like this: echo preg_replace('/http:\/\/www.mysite.com\/name\/(.*?)\//ie',"strtolower('\\1')",$str); The e modifier tells it that the thing in the second argument should be evaluated as PHP code. Hi, thanks a lot it works when i use the e modifier but it add extra \ at the end how can i remove this Quote Link to comment https://forums.phpfreaks.com/topic/171482-strtolower-not-working-inside-preg_replace/#findComment-904331 Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 Perhaps \\1 should be \1. Other than that, not sure. Quote Link to comment https://forums.phpfreaks.com/topic/171482-strtolower-not-working-inside-preg_replace/#findComment-904337 Share on other sites More sharing options...
.josh Posted August 23, 2009 Share Posted August 23, 2009 yeah sorry..dunno why I said x; meant e. Quote Link to comment https://forums.phpfreaks.com/topic/171482-strtolower-not-working-inside-preg_replace/#findComment-904559 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.