login about faq

Can anyone enlighten me what does thid code do?

$text=preg_replace('/\/i', '', $text);

asked Feb 17 '10 at 10:18

super%20duper's gravatar image

super duper
311

edited Feb 17 '10 at 10:49

Randell's gravatar image

Randell ♦♦
1.6k1529


If you'll set your php.ini variable error_reporting to E_ALL and display_errors to On, your code will output a warning similar to this:

Warning: preg_replace(): No ending delimiter '/' found in regex.php on line 1

Since backslash is an escape character, it treated the forward slash after the backslash as an escape to the forward slash character. Which means the regex forgot to specify what character to escape (instead of the forward slash) or it forgot to include the ending delimiter '/' while really escaping the forward slash character.

The i after the last forward slash is used to indicate a case-insensitive search.

link

answered Feb 17 '10 at 10:41

Randell's gravatar image

Randell ♦♦
1.6k1529

edited Feb 17 '10 at 11:08

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×63
×5

Asked: Feb 17 '10 at 10:18

Seen: 886 times

Last updated: Feb 17 '10 at 11:08