snakebit Posted April 26, 2008 Share Posted April 26, 2008 How to extract text from the anchor for example: <a href="www.phpfreaks.com">Some text</a> how to get this "Some text" Quote Link to comment https://forums.phpfreaks.com/topic/103032-extract-text-from-an-anchor/ Share on other sites More sharing options...
dooper3 Posted April 26, 2008 Share Posted April 26, 2008 You can do it with javascript if the link has an id by using this: var anchortext=document.getElementById('thelink').innerHTML; Quote Link to comment https://forums.phpfreaks.com/topic/103032-extract-text-from-an-anchor/#findComment-527790 Share on other sites More sharing options...
Daniel0 Posted April 26, 2008 Share Posted April 26, 2008 You can do it with javascript if the link has an id by using this: var anchortext=document.getElementById('thelink').innerHTML; Seeing as this was posted in the regex forum, it's quite unlikely he is seeking a Javascript solution. Could could get it like this: preg_match('#<a.*>(.*)</a>#iU', $string, $matches); $text = $matches[1]; Quote Link to comment https://forums.phpfreaks.com/topic/103032-extract-text-from-an-anchor/#findComment-527986 Share on other sites More sharing options...
snakebit Posted April 27, 2008 Author Share Posted April 27, 2008 You can do it with javascript if the link has an id by using this: var anchortext=document.getElementById('thelink').innerHTML; 10x, it's work perfect Quote Link to comment https://forums.phpfreaks.com/topic/103032-extract-text-from-an-anchor/#findComment-528234 Share on other sites More sharing options...
dooper3 Posted April 30, 2008 Share Posted April 30, 2008 You're right Daniel0. I didn't notice the forum it was in when I was replying, but it seems he liked the response anyway (though not sure what "10x, perfect" means?! Maybe it should read "100%, perfect". Or maybe he needs a new keyboard!) Quote Link to comment https://forums.phpfreaks.com/topic/103032-extract-text-from-an-anchor/#findComment-530720 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.