wrathican Posted November 3, 2008 Share Posted November 3, 2008 hey people i want to remove all text (and including) the <title></title> tags all i want is to have the text between them two tags. what would be the best way of going around this? thanks Quote Link to comment https://forums.phpfreaks.com/topic/131221-solved-removing-text-around-html-tags/ Share on other sites More sharing options...
DarkWater Posted November 3, 2008 Share Posted November 3, 2008 <?php $html = <<<HTML <html> <head> <title>Some title!</title> </head> <body> <p>Text....</p> </body> </html> HTML; preg_match('~<title>(.+?)</title>~is', $html, $matches); echo $matches[1]; Quote Link to comment https://forums.phpfreaks.com/topic/131221-solved-removing-text-around-html-tags/#findComment-681254 Share on other sites More sharing options...
wrathican Posted November 3, 2008 Author Share Posted November 3, 2008 Excellent! Thanks by the way i read your tutorial. its fantastic! Quote Link to comment https://forums.phpfreaks.com/topic/131221-solved-removing-text-around-html-tags/#findComment-681266 Share on other sites More sharing options...
wrathican Posted November 3, 2008 Author Share Posted November 3, 2008 now how do i remove the actual title tags? Quote Link to comment https://forums.phpfreaks.com/topic/131221-solved-removing-text-around-html-tags/#findComment-681282 Share on other sites More sharing options...
DarkWater Posted November 3, 2008 Share Posted November 3, 2008 Wait, do you want the text in between the title tags, or do you just want the title tags removed from a string? Quote Link to comment https://forums.phpfreaks.com/topic/131221-solved-removing-text-around-html-tags/#findComment-681290 Share on other sites More sharing options...
wrathican Posted November 3, 2008 Author Share Posted November 3, 2008 i want the text between the title tags, sorry if i wasn't clear. Quote Link to comment https://forums.phpfreaks.com/topic/131221-solved-removing-text-around-html-tags/#findComment-681297 Share on other sites More sharing options...
DarkWater Posted November 3, 2008 Share Posted November 3, 2008 Okay then, look at my code. $matches[1] contains the text in between the title tags. Quote Link to comment https://forums.phpfreaks.com/topic/131221-solved-removing-text-around-html-tags/#findComment-681322 Share on other sites More sharing options...
wrathican Posted November 3, 2008 Author Share Posted November 3, 2008 hmm, i did. when i echoed it out i didnt see anything, so i viewed the source and it was still between the tags. Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/131221-solved-removing-text-around-html-tags/#findComment-681431 Share on other sites More sharing options...
DarkWater Posted November 3, 2008 Share Posted November 3, 2008 Eh? Show me your full code. Quote Link to comment https://forums.phpfreaks.com/topic/131221-solved-removing-text-around-html-tags/#findComment-681466 Share on other sites More sharing options...
wrathican Posted November 4, 2008 Author Share Posted November 4, 2008 bah, i'm sorry. I was echoing out $matches[0], not $matches[1]. Thanks for your help DW, really shouldn't doubt your Regex skills Thanks Quote Link to comment https://forums.phpfreaks.com/topic/131221-solved-removing-text-around-html-tags/#findComment-681894 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.