sandy1028 Posted November 22, 2010 Share Posted November 22, 2010 How to remove any characters after '<br />' in a string. If input string is : By rd, RaeAnn Martin, Emily Sheene and Ebony Alcorn.<br /><br /> <p>Danville High School students: Output should be "By rd, RaeAnn Martin, Emily Sheene and Ebony Alcorn." Quote Link to comment https://forums.phpfreaks.com/topic/219432-remove-strings/ Share on other sites More sharing options...
Psycho Posted November 22, 2010 Share Posted November 22, 2010 $input = "By rd, RaeAnn Martin, Emily Sheene and Ebony Alcorn.<br /><br /> <p>Danville High School students:"; $output = preg_replace('#<br \/>.*#', '', $input); Quote Link to comment https://forums.phpfreaks.com/topic/219432-remove-strings/#findComment-1137820 Share on other sites More sharing options...
jim_keller Posted November 22, 2010 Share Posted November 22, 2010 I would actually change the regex above to match <br />, < BR>, < br / >, etc by doing the following. It's never good to assume you're getting well formed HTML: $input = "By rd, RaeAnn Martin, Emily Sheene and Ebony Alcorn.<br /><br /> <p>Danville High School students:"; $output = preg_replace('#<\s*br\s*\/?\s*>.*#i', '', $input); Quote Link to comment https://forums.phpfreaks.com/topic/219432-remove-strings/#findComment-1138031 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.