Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Newbie question: eregi() to preg_match()

Featured Replies

Hi all.

 

I'm not a PHP person so please bear with me.

 

I need to remove eregi() and replace it with preg_match(). The line that needs updating is:

return (eregi("\r", $s) || eregi("\n", $s) || eregi("%0a", $s) || eregi("%0d", $s)) ? TRUE : FALSE;

Would the following be correct and achieve the same as the above?

return (preg_match("/\r/i", $s) || preg_match("/\n/i", $s) || preg_match("/%0a/i", $s) || preg_match("/%0d/i", $s)) ? TRUE : FALSE;

As you can see, I've just added delimiters and a trailing 'i', but I'm not sure whether I need to escape anything, bearing in mind it's using double quotes. If anyone can point me in the right direction I'd appreciate it.

 

Thanks.

  • Author

OK ignore the above, let's make this simpler :) I just need to update the following two to preg_match()

eregi("\n", $s)
eregi("%0a", $s)

General rule is to add delimiters and a trailing 'i', like so..

preg_match("/\r/i", $s)
preg_match("/%0a/i", $s)

But in addition to this, do escapes (how many?) also need to be added before the \r and %0a?

Edited by Spinoza

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.