Issue with explode()

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

danboyle
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Feb 18, 2014 6:59 am

Issue with explode()

Postby danboyle » Tue Feb 18, 2014 8:14 am

Hello,

I am getting an unexpected result from explode().

$AddressStr = "Dove Dental Centres 9A - 769 Southdale Road East, London, ON, N6E 3B9, Canada , 226-270-1071"


I am using the function as such:

$AddressFields = explode(",",$AddressStr);

The output of the array created is the following:

Array
(
[0] => Dove Dental Centres
9A - 769 Southdale Road East
[1] => London
[2] => ON
[3] => N6E 3B9
[4] => Canada

[5] => 226-270-1071
)

There is a linefeed being added to the first field after Centres and to the 4 field after Canada. A line feed was not present in the initial string so where is this coming from?

Dan

danboyle
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Feb 18, 2014 6:59 am

Re: Issue with explode()

Postby danboyle » Tue Feb 18, 2014 8:31 am

I notice that the print_r function displays the field values differently then the echo function.

If I do this:

echo "$AddressField[0]";

I get:

Dove Dental Centres 9A - 769 Southdale Road East

No linefeed issue.

But the print_r function shows field zero as:

[0] => Dove Dental Centres
9A - 769 Southdale Road East

It has added a line feed. This is also the spot that is causing me an error in parsing this information so I would like to understand it.

Dan


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 4 guests

cron