开发者

Parse error: syntax error, unexpected '{' in PHP? [closed]

开发者 https://www.devze.com 2023-03-20 07:29 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

S开发者_如何学Pythono I got this error:

Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\scanner\mine.php on line 112

On this line:

if(preg_match("inurl:", $text) {

Its part of a "Clean" function:

  function Clean($text) {
        if(preg_match("inurl:", $text) {
            str_replace("inurl:", "", $text);
            return htmlspecialchars($text, ENT_QUOTES);
        } else {
            return htmlspecialchars($text, ENT_QUOTES);
        }
  }

How can I fix it?


Two problems, One closing ) and a missing semicolon after str_replace, also you should know your str_replace won't do anything in your code so i added $text = ... :)

  function Clean($text) {
        if(preg_match("inurl:", $text)) {
            $text = str_replace("inurl:", "", $text);
            return htmlspecialchars($text, ENT_QUOTES);
        } else {
            return htmlspecialchars($text, ENT_QUOTES);
        }
  }


Add another ):

if(preg_match("inurl:", $text)) {


You're missing the closing ) on your if statement.

Should be:

if(preg_match("inurl:", $text)) {

You're also missing your statement terminator on the string replace. That should be:

str_replace("inurl:", "", $text);


You left out the ) for the if condition.

  if
    (
      preg_match(
        "inurl:", $text
      ) 
    {


The if clause is superfluous anyway. The following function is equivalent to the original version (sans the non-compiling regex pattern).

function Clean($text)
{
    $text = str_replace("inurl:", "", $text);
    return htmlspecialchars($text, ENT_QUOTES);
}

If the string you want to replace is not found in the haystack, str_replace won't do anything. So it is safe to run the function unconditionally.

In the original version, you'd also have to surround the regex pattern for preg_match with delimiters (see: http://www.php.net/manual/en/regexp.reference.delimiters.php). (In this case, strpos would do the job, too.)

0

精彩评论

暂无评论...
验证码 换一张
取 消