Jump to content

preg_replace


stubarny

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.