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." 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); 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); Link to comment https://forums.phpfreaks.com/topic/219432-remove-strings/#findComment-1138031 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.