stubarny Posted January 26, 2007 Share Posted January 26, 2007 Hi everyone,I'm writing a bit of code to delete "[[:<:]]" and "[[:>:]]" from strings in an array. Only I'm getting confused because the "[" and "]" symbols have special meaning that I can't figure out how to surpress. I tried putting forward slashes and backward slashes in front of the symbols but no luck.If you could provide any pointers I'd be very grateful!Thanks,Stu------------------------------------------------------------------------------foreach($terms_db as $term_db) { $term_db = preg_replace("[[:<:]]", "", $term_db); $term_db = preg_replace("[[:>:]]", "", $term_db); $terms_db_no_word_boundaries[] = $term_db; } Link to comment https://forums.phpfreaks.com/topic/35829-preg_replace/ Share on other sites More sharing options...
Orio Posted January 26, 2007 Share Posted January 26, 2007 Escape it using using a backslash.[code]<?phpforeach($terms_db as $term_db){ $term_db = preg_replace("\[\[:<:\]\]", "", $term_db); $term_db = preg_replace("\[\[:>:\]\]", "", $term_db); $terms_db_no_word_boundaries[] = $term_db;}?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/35829-preg_replace/#findComment-169858 Share on other sites More sharing options...
stubarny Posted January 26, 2007 Author Share Posted January 26, 2007 OK thanks for your help, I've got it working with forward slashes at the start and end of the search string as well as the backslashes before the "[" and "]" symbols:foreach($terms_db as $term_db){ $term_db = preg_replace("/\[\[:<:\]\]/", "", $term_db); $term_db = preg_replace("/\[\[:>:\]\]/", "", $term_db); $terms_db_no_word_boundaries[] = $term_db;} Link to comment https://forums.phpfreaks.com/topic/35829-preg_replace/#findComment-169869 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.