PHP raising error when parsing regular expression [duplicate] - php

This question already has answers here:
Warning: preg_match() [function.preg-match]: Unknown modifier '/' [duplicate]
(2 answers)
Closed 8 years ago.
I have a PHP function to validate e-mail fields. In my PHP file, I receive below error:
Warning: preg_match(): Unknown modifier '_' in C:\xampp\htdocs\validator.inc.php on line 28
My PHP file is:
<?php
define("EMAIL_MASK", "^[-!#$%&'*+/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+/0-9=?A-Z^_a-z{|}~])*#[a-zA-Z](-?[a-zA-Z0-9])*(\.[a-zA-Z](-?[a-zA-Z0-9])*)+$");
(...)
function isEmailValid($email)
{
return !empty($email) && preg_match(EMAIL_MASK, $email); <---- This is the line raising the error
}
(...)
?>
What am I doing wrong?

You failed to put the PHP regex delimiters.
define("EMAIL_MASK", "~^[-!#$%&'*+/0-9=?A-Z^_a-z{|}\~](\.?[-!#$%&'*+/0-9=?A-Z^_a-z{|}\~])*#[a-zA-Z](-?[a-zA-Z0-9])*(\.[a-zA-Z](-?[a-zA-Z0-9])*)+$~");
| |

Related

How do I fix an error generated while opening my PHP application [duplicate]

This question already has answers here:
Fatal error: Declaration of .. must be compatible with .. PHP
(6 answers)
PHP: What does this error mean? Abstract method must be compatible?
(1 answer)
Closed yesterday.
I am getting an error that I have not been able to solve:
Fatal error: Declaration of & ADODB_mysql::MetaColumns($table) must be compatible with ADOConnection::MetaColumns($table, $upper = true) in /home/kajozbiz/easyloanman.kajozbizhub.africa/lib/drivers/adodb-mysql.inc.php on line 126
And below is the code on the line 126:
}
function &MetaColumns($table)
{
if ($this->metaColumnsSQL) {
global $ADODB_FETCH_MODE;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
I have tried removing the line but the error move to the next line and so forth

How to migrate php preg_replace to preg_replace_callback? [duplicate]

This question already has answers here:
Replace preg_replace() e modifier with preg_replace_callback
(3 answers)
Closed 1 year ago.
Given line:
"$className = "MForm" . preg_replace('/(?:^|_)(.?)/e',"strtoupper('$1')",$name);"
isn't working with PHP7. I changed it to:
"$className = "MForm" . preg_replace_callback('/(?:^|_)(.?)/',"strtoupper('$1')",$name);"
It seems not to be correct, due to warning printout:
"Warning: preg_replace_callback(): Requires argument 2, 'strtoupper('$1')', to be a valid callback in /.../components/com_proforms/formlib/init.php on line 59"
How can I handle strtoupper('$1') correctly in preg_replace_callback()?
Replace "strtoupper('$1')" with
function($matches) { return strtoupper($matches[1]); }
No quotes around it.

I need assistance with eregi - preg_match [duplicate]

This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 7 years ago.
I was getting the following error:
Deprecated: Function eregi() is deprecated in /home/herbalhe/public_html/admin/includes/auth.inc.php
So I searched and found that I should be using preg_match() instead of eregi(). So I made the changes and now I am getting this error:
Warning: preg_match(): Unknown modifier 'p' in /home/herbalhe/public_html/admin/includes/auth.inc.php
The code on that line is:
if (preg_match(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) ||
preg_match(".inc.php",$_SERVER['PHP_SELF']))
Any idea what I should now?
It should be:
preg_match("/\.inc\.php$/i", $HTTP_SERVER_VARS['PHP_SELF'])

$_get and file_get_contents don't work together [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I have a PHP script that basically tries to convert the string it gets from:
https://camwijs.nl/system/avatarimage.aspx?username=
to
https://www.habbo.com/habbo-imaging/avatarimage?figure=
If I run the code it just gives me an page with the error message:
Warning: file_get_contents(https//camwijs.nl/system/avatarimage.aspx?username=nomakta): failed to open stream: No such file or directory in /home/u750368594/public_html/v1/avatar/avatar.php on line 4
http://www.habbo.com/habbo-imaging/avatarimage?figure=
Here is the code:
<?php
// gets avatar with GR
$camwijsAvatarurl = "https//camwijs.nl/system/avatarimage.aspx?username=".htmlspecialchars($_GET["name"]);
// displays avatar link here
echo 'http://www.habbo.com/habbo-imaging/avatarimage?fgure=' .file_get_contents($camwijsAvatarurl);
?>
You have an extra trailing . at the end of line 2, which throws a syntax error for improper concatenation:
Parse error: syntax error, unexpected ';' in ... on line 2
Either remove that . or add " " (but only if you're planning on concatenating further)

PHP Warning: Illegal String Offset attributes [duplicate]

This question already has answers here:
Illegal string offset Warning PHP
(17 answers)
Closed 8 years ago.
Can someone help me out please. My error log is getting blown up by this error and I cannot figure out why.
PHP Warning: Illegal string offset 'attributes' in xml.php on line 377
Here is the xml.php file > http://pastebin.com/SL8Kt7Zu
On the line 377 check if the index is set before trying to access it:
if(isset($v['attributes'])) {

Categories