Preg_Match error - Warning!

Hey,

I’m trying to finish this little bit of script, but keep getting an error message:

Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in

I have tried using different delimiters, in different areas of the code. Once i have done it i check it over with syntax online and get no error. However, when i visit my website, i continue to get the error. Below is the bit of code i need help with, if somebody can :slight_smile:

[php]* Please check

  • http://www.texmedia.de
  • for Bugfixes, Updates and Support/
    ******************************************************************************************/
    If(preg_match(basename(FILE) , $HTTP_SERVER_VARS[REQUEST_URI]))
    die (“You can’t access this file directly! Please go to the startpage!”);

$VERSIONS[basename(FILE)] = “3.0”;
$TMP[’%[GRIDS]%’] = ‘’;[/php]

Line 23 - “Please check” - i cant understand why i get the error on line 23 as it is just a plain text line.

Thanks in advance,

Andy

First of all is this exactly how that code looks or did you miss a /* at the beginning? It should be:
(notice the syntax highlighting difference from mine to yours now that the comment is using valid syntax)

[php]/*

  • Please check
  • http://www.texmedia.de
  • for Bugfixes, Updates and Support/
    ******************************************************************************************/[/php]

Also, you have set no delimiters on your preg_match function. Examples below:
[php]$testVar = ‘my/test/data’;
preg_match(’/’.preg_quote($testVar,’/’).’/’,$subject,$matches);//Using preg_quote with a second parameter of ‘/’ ensures that any forward slashes (our delimiter) are escaped
preg_match(’#’.$testVar.’#’,$subject,$matches);//No need to escape forward slashes, as this time our delimiter is a ‘#’ and our test string doesn’t contain any - if it did we would have to use preg_quote($testVar,’#’,) or use a different delimiter[/php]

The delimiter for preg_match can be anything, as long as any occurrences within the test string are escaped, so that it isn’t terminated too early.

Thanks for the response,

I shouldn’t have put the text part in there, it turns out ir is just the Preg_match part that isn’t working. That is also line 23, i miscounted the lines.

The code is exactly like this:

[php]If(preg_match(basename(FILE) , $HTTP_SERVER_VARS[REQUEST_URI]))
die (“You can’t access this file directly! Please go to the startpage!”);

$VERSIONS[basename(FILE)] = “3.0”;
$TMP[’%[GRIDS]%’] = ‘’[/php]

I tried this:

[php]If(preg_match(’/(basename(FILE)/i) , $HTTP_SERVER_VARS[REQUEST_URI]))
die (“You can’t access this file directly! Please go to the startpage!”);

$VERSIONS[basename(FILE)] = “3.0”;
$TMP[’%[GRIDS]%’] = ‘’[/php]

I checked the above code with syntax check and no errors were found. However, once uploading the file to my server and accessing it on my website i get the following errors:

Warning: Division by zero in /home/content/41/10699241/html/grids.php on line 23

Warning: preg_match() [function.preg-match]: Empty regular expression in /home/content/41/10699241/html/grids.php on line 23

Thanks for the reply :slight_smile:

If the syntax highlighting on your post hasn’t made it clear to you, see below. I would also suggest you use an IDE such as Netbeans, which will make it clear when simple mistakes have been made.

You haven’t closed the string for the first parameter of preg_match and the basename function hasn’t been concatenated and is therefore being treated as plain text. The line should be:

[php]if(preg_match(’/’.basename(FILE).’/i’, $HTTP_SERVER_VARS[REQUEST_URI]))
{
die (“You can’t access this file directly! Please go to the startpage!”);
}[/php]

omg, thankyou!

i did do the (’/’. last night, but finished it like this /i’ instead of ‘/i’

such a simple mistake.

thanks, the error has gone :slight_smile:

Andy

Hi Andy,

I’m glad you have sorted your issue.

William

I have just one more, slight issue.

Everything above it working as it should, but here is another piece i can’t seem to hack. I am completely new to all this, but promise that i have sat and puzzled over each piece to try and fix it myself before coming here… but to no avail on this one too :confused:

Same error as before:

Function ereg() is deprecated in /home/content/41/10699241/html/STNcontrol/editor/class.rich.php on line 2120

Here is the bit of code that is giving me trouble:

[php]if(ereg(“MSIE ([0-9|.]+)”, $user_agent, $regs) &&
ereg(“Win”, $user_agent) && !strstr($user_agent, ‘Opera’)){
$rich_browser = ‘msie’;
}else{[/php]

Thanks once again, you guys have been a great help so far.

Andy

Try changing:

[php]ereg(“Win”,$user_agent)[/php]

To:

[php]ereg(‘Win’,$user_agent)[/php]

I FIXED IT!!!

Learning something…

Thanks smokey php, it was because of your ‘highlighting’ reference that i spotted what was wrong.

:slight_smile:

Hi Andy,

I’m glad you have sorted your issue.

William

Good to hear, in regards to the ereg() issue - that function is now deprecated, the function you should be using in place of ereg() is preg_match() - the main difference in terms of how you will be using it in your code is that preg_match requires delimiters whereas ereg doesn’t.

For further clarification remember you can always check the php.net site for reference.

Sorry if i start you bug you all, but i give up with this one. I even downloaded NetBeans, but still stuck…

[php] if(ereg(“Mozilla/([0-9|.]+)”, $user_agent, $regs) &&
ereg(“Gecko”, $user_agent) && (double)$regs[1]>=5.0 &&
ereg(“rv:([0-9|.]+)”, $user_agent, $v_regs) &&
(double)$v_regs[1]>=1.4){
$is_ns = true;
$msie_version = (double)$regs[1];[/php]

I changed it to preg_match and tried different delimiters, but i can’t hack this bit :confused:

The above code is the original :slight_smile:

Thanks again

Andy

Sponsor our Newsletter | Privacy Policy | Terms of Service