PHP Parse error

I am getting this error with the code below
PHP Parse error:  syntax error, unexpected 'box\xe2\x80\x99' (T_STRING) in /path to/wordpress/wp-content/themes/flatsome-child/functions.php on line 10

Open in new window

// Add custom Theme Functions here
add_filter('woocommerce_package_rates', 'wf_hide_fedex_for_po_box_shipment', 10, 2);
function wf_hide_fedex_for_po_box_shipment($available_shipping_methods, $package){
    $shipping_method_to_hide = 'wf_fedex_woocommerce_shipping';
    global $woocommerce;
    $address  = ( !empty( $woocommerce->customer->get_shipping_address_1() ) ) ? $woocommerce->customer->get_shipping_address_1() : $woocommerce->customer->get_billing_address_1();
    $postcode = ( !empty( $woocommerce->customer->get_shipping_postcode() ) ) ? $woocommerce->customer->get_shipping_postcode() : $woocommerce->customer->get_billing_postcode();

   if( strstr( $address, ‘pobox’ ) || strstr( $postcode, ‘pobox’ ) || strstr( $address, ‘po box’ ) || strstr( $postcode, ‘po box’ ) || strstr( $address, ‘p.o. box’ ) || strstr( $postcode, $
strstr( $address, ‘P.o. box’ ) || strstr( $postcode, ‘P.o. box’ ) || strstr( $address, ‘po. box’ ) || strstr( $postcode, ‘po. box’ ) || strstr( $address, ‘Po Box.’ ) || strstr( $postcode, $
        foreach ($available_shipping_methods as $shipping_method => $value) {
            if( strpos( $shipping_method, $shipping_method_to_hide ) !== false ) {
    return $available_shipping_methods;

Open in new window

Line 10 is where the if statement begins.  I have a regex I used in a different cart.  What would be the syntax to add this method?  I am new to oop.

static public function is_pobox_address($address) {
                $po_pattern1 = '/^(([pP]{1}(.*?)(\s+)?[oO]{1}(.*?))+?(\s+)?([0-9]+))+?/';
                $po_pattern2 = '/^([bB][oO]?[xX]?)(\s+)?([0-9]+)+?/';
                if (preg_match($po_pattern1, $address) || preg_match($po_pattern2, $address)) {
                        return true;
                else {
                        return false;

Open in new window

Help me to stop this error.  Thanks
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dillyn BarberCIOCommented:
Worth a shot doing your regex along the lines of this:
preg_match('/^(([pP]{1}(.*?)(\s+)?[oO]{1}(.*?))+?(\s+)?([0-9]+))+?/', $po_pattern1, $address);
$the_preg = $match[1];
preg_match('/^([bB][oO]?[xX]?)(\s+)?([0-9]+)+?/', $po_pattern2, $address);
$the_preg2 = $match[2];  

Open in new window

Results may vary, doing it this way works for me every time though. Then you can just return or echo $match[1]; or $match[2];
Julian HansenCommented:
Rather use stristr() instead of strstr() - it reduces your comparisons to only the lower case versions of the string.

Your question seems to have two parts
1. You have an error
2. You want to incorporate the RegEx for the PO Address

Can we focus on just one of these for now.

Where is the string box\xe2\x80\x99 in your source - the error is referring to it - but it is not there?
sharingsunshineAuthor Commented:
Dillyn, can you show how this would be implemented into my code?

Julian, you are correct the string of code making the error was obvious.  It turns out my copy and paste from the original was incomplete.  Since my comparisons are upper and lower case I won't be able to use your suggestion.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Julian HansenCommented:
Since my comparisons are upper and lower case I won't be able to use your suggestion.
I don't understand this bit - why is it important whether you compare PO BOX to po box and not get a match?

My suggestion is to reduce the comparison to a case neutral one to reduce the number of possible combinations. To do that you use a function that is case agnostic - such as stristr()
sharingsunshineAuthor Commented:
The customer can decide to put in the phrase PO Box in many different iterations.  It is my "limited" understanding of php that the if test logic would be case sensitive.  Thus, the reason for my statement.

If this is incorrect then please by all means please explain.
Julian HansenCommented:
What we are trying to do here is reduce the number of comparisons needed to be made to determine if the input is correct.

It is unnecessary to have a separate process for comparing PO BOX and po box as they are essentially identical except for case so using a case insensitive compare will greatly reduce the number of comparisons needed to be made.

What you need to ask is are you going to allow for all possible variations or try and target the majority and coax clients to use one of the acceptable set.

For instance valid input on a PO box would be

PO Box ###
P.O. Box ###

Ignoring case.
A regex for this might therefore be

Open in new window

This regex is saying
match all strings that begin with a 'p' (any case by the /i at the end of the expression)
followed optionally by a '.' and 0 or more spaces (ignore white space)
followed by an 'o' (again no case)
followed optionally by a '.' and at least 1 space
followed by the word 'box' (no case)
followed by at least 1 space
followed by 1 or more digits.

The ^ at the beginning of the expression says match from the start of the string
The $ at the end says match to the end of the line
The /i means ignore case

This example demonstrates how to use it
$input = array(
"PO Box 123",
"P.O. Box 123",
"PO. Box 123",
"P.O Box 123",
"P O Box 123",
"P Box 123",
"PO Box123",
"PO Box",
"P. Box 123",
"po box 123",
"p.o. box 123",
"po. box 123",
"p.o box 123",
"p o box 123",
"p box 123",
"po box123",
"po box",
"p. box 123"

$pattern = "/^p\.?\s*o\.?\s+box\s+\d+$/i";

foreach($input as $i) {
	if (preg_match($pattern, $i, $matches)) {
		echo "{$i} is a match" . print_r($matches, true) . "<br>";
	else {
		echo "{$i} failed to match<br>";

Open in new window

PO Box 123 is a matchArray ( [0] => PO Box 123 )
P.O. Box 123 is a matchArray ( [0] => P.O. Box 123 )
PO. Box 123 is a matchArray ( [0] => PO. Box 123 )
P.O Box 123 is a matchArray ( [0] => P.O Box 123 )
P O Box 123 is a matchArray ( [0] => P O Box 123 )
P Box 123 failed to match
PO Box123 failed to match
PO Box failed to match
P. Box 123 failed to match
po box 123 is a matchArray ( [0] => po box 123 )
p.o. box 123 is a matchArray ( [0] => p.o. box 123 )
po. box 123 is a matchArray ( [0] => po. box 123 )
p.o box 123 is a matchArray ( [0] => p.o box 123 )
p o box 123 is a matchArray ( [0] => p o box 123 )
p box 123 failed to match
po box123 failed to match
po box failed to match
p. box 123 failed to match

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sharingsunshineAuthor Commented:
Thanks for the explanation.  That will save a lot of steps.
Julian HansenCommented:
You are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.