views:

36

answers:

2

Hello

The following code keeps giving me this eroor

  "Parse error: syntax error, unexpected T_VARIABLE in ..."

?

   $query_string = 'this is a test... "this is in quotes" mmm..chicken burgers... yummm...';
   preg_match_all("/\".*\"|[^\s]*/",  ­ $query_string, $matches);
   echo "Matches:";
   foreach($matches[0] as $token) {
          echo $token . "<br />";
   }

it is from this web page

Thanks

A: 

Have you looked at the line referred to in the Error Message you noted? Have you looked at the lines preceding that line, to ensure that you have ended each line with the semi-colon ";", that you have used the correct operators for joining variables ".", etc.?

This sounds like a simple PHP Syntax error.

I just ran the following code on my XAMPP server with no error messages apparent:

<?php

$query_string = 'this is a test... "this is in quotes" mmm..chicken burgers... yummm...';
preg_match_all("/\".*\"|[^\s]*/", $query_string, $matches);
echo "Matches:";
foreach($matches[0] as $token) {
  echo $token . "<br />";
}
Lucanos
Thanks, the line which has the error is preg_match_all() I am sure the syntax is OK, the problem might be caused by the pattern used in regex
ahmed
When I copied and pasted the code, as you had it, there was a minus sign "-" before `$query_string` on the line commencing with `preg_match_all(...`
Lucanos
Thanks, strange code behaviour because I couldn't find the minus "-" sign ;however, your code works perfect, Thanks
ahmed
A: 

As Col. Shrapnel noted, you have hidden dash symbol (173 decimal, Hex 00ad) in your code right before $query_string. Remove that and you'll be much better.

Update: to be exact, you have [comma], [space], [space], [hidden dash], [space], '$query_string'.

ash108