mry Posted June 19, 2012 Share Posted June 19, 2012 Hi , I want to add title to existing <a href> and update the same for the userid in the url. $srting = '<a href="mysite/user/39">Pooja</a><a href="mysite/user/58">Harsha</a>some text here'; i want the fetch the <a> tags separately from the above url and using the userid i need to update the <a href> with title tag like this Expectd output: $srting = '<a href="mysite/user/39" title="Pooja">Pooja</a><a href="mysite/user/58" title="Harsha">Harsha</a>some text here'; Please tell how to do this? Thanks in advance... Quote Link to comment https://forums.phpfreaks.com/topic/264430-get-the-anchor-tag-for-userid-in-the-url/ Share on other sites More sharing options...
scootstah Posted June 19, 2012 Share Posted June 19, 2012 This seems to work: $string = '<a href="mysite/user/39">Pooja</a><a href="mysite/user/58">Harsha</a>some text here'; $string = preg_replace('/<a href="(.+?)">(.+?)<\/a>/i', '<a href="$1" title="$2">$2</a>', $string); Quote Link to comment https://forums.phpfreaks.com/topic/264430-get-the-anchor-tag-for-userid-in-the-url/#findComment-1355144 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.