strlen() returns an unexpected number
Posted: Mon Jun 29, 2009 12:26 pm
I'm trying to parse the following string:
API_Authenticate 0 No error 4_beiz23n4u_bymy8i_b_cbyyzg4wwerpnd34kp4hd4kiakf_b737vy85rv2ge_ 57007048.d2m4
(This is the string returned from a call to file_get_contents that references a URL that returns XML -- i.e. file_get_contents(http://foo.com?etc..), where directly referencing http://foo.com?etc would normally return XML))
The value I'm interested in is the 4_beiz23n4u...; I need to extract that from the string (it gets passed as a parameter in a different URL).
Unfortunately, the PHP I'm using doesn't seem to be behaving how I expect... which means, I'm probably doing it wrong.
here's what I'm doing:
What's happening is this: $ret is returning the string at the beginning of the post ("API_Authenticate...") just fine. (Line 1)
explode() does not seem to work as advertised, though. It is lumping "error 4_beiz23n4u_bymy8i_b_cbyyzg4wwerpnd34kp4hd4kiakf_b737vy85rv2ge_ 57007048.d2m4 " into the $ticket variable. I've tried adding other variables to list() and I get the same result, strangely). (Line 3)
ltrim() (Line 5) works OK, but it tells me the resulting string has a strlen() of 139, hence the call to rtrim().
Rtrim() (Line 7) does nothing noticeable; the strlen() after rtrim() is still 139.
This renders the call to substr() useless, unfortunately. (Line 9)
So... my dilemma (and apologies in advance for the horrid variable names): how do I get that huge string I need out of the original result from file_get_contents()? I'm stumped here as to why it's not behaving how I want it to.
Thanks in advance!
API_Authenticate 0 No error 4_beiz23n4u_bymy8i_b_cbyyzg4wwerpnd34kp4hd4kiakf_b737vy85rv2ge_ 57007048.d2m4
(This is the string returned from a call to file_get_contents that references a URL that returns XML -- i.e. file_get_contents(http://foo.com?etc..), where directly referencing http://foo.com?etc would normally return XML))
The value I'm interested in is the 4_beiz23n4u...; I need to extract that from the string (it gets passed as a parameter in a different URL).
Unfortunately, the PHP I'm using doesn't seem to be behaving how I expect... which means, I'm probably doing it wrong.
here's what I'm doing:
Code: Select all
$ret = file_get_contents('[i]url[/i]');
list($action, $errcode, $errtext, $ticket) = explode(" ", $ret);
$ticked = ltrim($ticket, "ero "); // necessary to trim "error" from front of string
echo "Strlen(Ticked) is ".strlen($ticked)."<br />";
$ticked2=rtrim($ticked);
echo "Strlen(Ticked2) after rtrim() is ".strlen($ticked2)."<br />";
$ticked3 = substr($ticked2, 0, -15);
echo "Ticked3 is ".$ticked3."<br />";explode() does not seem to work as advertised, though. It is lumping "error 4_beiz23n4u_bymy8i_b_cbyyzg4wwerpnd34kp4hd4kiakf_b737vy85rv2ge_ 57007048.d2m4 " into the $ticket variable. I've tried adding other variables to list() and I get the same result, strangely). (Line 3)
ltrim() (Line 5) works OK, but it tells me the resulting string has a strlen() of 139, hence the call to rtrim().
Rtrim() (Line 7) does nothing noticeable; the strlen() after rtrim() is still 139.
This renders the call to substr() useless, unfortunately. (Line 9)
So... my dilemma (and apologies in advance for the horrid variable names): how do I get that huge string I need out of the original result from file_get_contents()? I'm stumped here as to why it's not behaving how I want it to.
Thanks in advance!