1

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.

j0k
  • 22,600
  • 28
  • 79
  • 90
Ross Fuhrman
  • 638
  • 4
  • 13
  • 26

2 Answers2

3

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

  • I did that 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." I will update my question. – Ross Fuhrman Feb 11 '13 at 19:54
  • It seems there is some other problem than match. Try var_dump it –  Feb 11 '13 at 19:55
  • 1
    Thank you, this answered my original question. I ended up upgrading CodeIgniter to fix the rest of my problems. – Ross Fuhrman Feb 11 '13 at 22:48
2
if(substr($pref, -1) !== '/'){

}

OR:

if($pref[strlen($pref)-1] !== '/' ){
 //not found
}
  • exactly how is the end of a string supposed to contain a boolean false? OP wants to check for a `/` at the end of the line, not a false. – Marc B Feb 11 '13 at 19:37