Jump to content

strtolower not working inside preg_replace


ibinod

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.