PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mrbeatnik
Forum Newbie
Posts: 4 Joined: Thu Aug 11, 2005 8:47 am
Post
by mrbeatnik » Thu Aug 11, 2005 8:58 am
Hi all. Hope you can help, this is driving me crazy...
Working: Hard coded string.
Code: Select all
$mess="just testing";
$p1mess = explode(' ', $mess);
This works fine, resulting in:
Code: Select all
$mess = just testing
$p1mess[0] = just
$p1mess[1] = testing
Not Working: String passed in packet.
Code: Select all
$mess=$this->frominc; //(retreive "just testing")
$p1mess = explode(' ', $mess);
This does not works at all, resulting in:
Code: Select all
$mess = just testing
$p1mess[0] =
$p1mess[1] =
$this->frominc is a being intercepted from a packet. I have a feeling it might be arriving as XML. If I echo $mess, it shows the complete string, but it is NOT separating with the ' ' (space).
Working: String passed in packet.
Code: Select all
$mess=$this->frominc; //(retreive "just1testing")
$p1mess = explode('1', $mess);
This works fine, resulting in:
Code: Select all
$mess = just1testing
$p1mess[0] = just
$p1mess[1] = testing
Can anyone help out?
I need to explode on ' ' (space).
Thanks!
Last edited by
mrbeatnik on Thu Aug 11, 2005 10:35 am, edited 1 time in total.
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Thu Aug 11, 2005 9:03 am
There is nothing wrong with explode...
There must be something wrong with your
You could echo it... before you pass it to explode.. So you know for sure what you are exploding.
Btw, it's possible that the string contains a tab ("\t") instead of a space. Might also explain the weird behaviour.
nielsene
DevNet Resident
Posts: 1834 Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA
Post
by nielsene » Thu Aug 11, 2005 9:05 am
As a long shot, you might want to see if the arriving packet is using some nonstandard encoding. Perhaps the space is not getting encoded to its normal codepoint?
mrbeatnik
Forum Newbie
Posts: 4 Joined: Thu Aug 11, 2005 8:47 am
Post
by mrbeatnik » Thu Aug 11, 2005 9:12 am
I'm convinced that the space is not being used as "normal", since it can correctly explode the string that uses the "1" other than " "(space).
When I echo the $mess, it gives it exactly as it should be. Of course, the webpage doesn't always display special chars (\t). I will check for that. I'm sure it's XML that is being returned....
"<body>just testing</body>" is the message part of the packet.
Will check the \t issue, any other suggestions would be lovely however
Thanks people!
nielsene
DevNet Resident
Posts: 1834 Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA
Post
by nielsene » Thu Aug 11, 2005 9:17 am
try using
That would at least change %32 back to space (which the browser would also do masking the problem.)
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 11, 2005 9:20 am
try showing it with:
Code: Select all
echo '<pre>'.htmlentities(var_export($mess,true),ENT_QUOTES).'</pre>';
// could also try
echo '<pre>'.var_export(rawurlencode($mess),true).'</pre>';or variants thereof
mrbeatnik
Forum Newbie
Posts: 4 Joined: Thu Aug 11, 2005 8:47 am
Post
by mrbeatnik » Thu Aug 11, 2005 10:35 am
Code: Select all
echo '<pre>'.htmlentities(var_export($mess,true),ENT_QUOTES).'</pre>';
Produces:
Code: Select all
'<message from=\'blah@blah.com\' to=\'blah1@blah.com\' id=\'1345\' type=\'chat\'><body>just testing</body><x xmlns=\'jabber:x:event\'><composing/></x></message>'
As I thought, the <body> tags are still being caught, so...
Code: Select all
$newmess = explode('<body>', $mess);
$new1mess = explode('</body>', $newmess[1]);
$p1mess = explode(' ', $new1mess[0]);
Which gives:
Code: Select all
$p1mess[0]=just
$p1mess[1]=testing
Can't believe I didn't already try that...
Thanks for the help everyone!
Just one thing tho, is there a quicker piece of code to do what I did in those three lines? Not that it matters too much..!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 11, 2005 10:53 am
if you used the xml functions/classes in php, it could make life a lot easier..
there's of course regular expressions that can retrieve the data too..