phppreg-matchereg

Equivalent of ereg() call


My server is running on php 5.3 now and I need to replace this call to ereg:

if (ereg("/$", $pref) === FALSE) 
{
  $pref .= '/';
}

I have tried this, among other things without any success:

if (preg_match('~/$~', $pref) === FALSE)

This results in http://example.com/index.phpwww/browse If it makes any difference, this is a CodeIgniter 1.6.1 app that I've inherited.

I tried this:

if (ereg("/$", $pref) === 0) 

as @PeterM suggested and now going to http://example.com takes me to http://example.com/index.php/www/browse , but that gives me the message of "The URI you submitted has disallowed characters." Is that be a valid CodeIgniter URL? Maybe I messed something up elsewhere in the code?

I changed line 126 of codeigniter/application/config/config.php to be:

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

and I still get the message.


Solution

  • Compare it against 0, not false. preg_match returns number of matches. It returns false only on error.