Can someone please explain why is the following code outputting some Chinese instead of breaking down the string passed in the function into an array.

<?php
// define URL
$url = "http://www.somewebsite.com:80/community/columns/trog/article.php?id=79&page=2";
// parse URL into associative array
$data = parse_url($url);
// print URL components
foreach ($data as $k => $v){
echo "$k: $v \n";
}
?>

thanks in advance!

Can someone please explain why is the following code outputting some Chinese instead of breaking down the string passed in the function into an array.

<?php
// define URL
$url = "http://www.somewebsite.com:80/community/columns/trog/article.php?id=79&page=2";
// parse URL into associative array
$data = parse_url($url);
// print URL components
foreach ($data as $k => $v){
echo "$k: $v \n";
}
?>

thanks in advance!

hi bibiki,

i think you should change the condition
foreach ($data as $k => $v){
to
foreach ($data as $k <= $v){
or
foreach ($data as $k == $v){

there's always an error with the
foreach ($data as $k => $v){
condition even after changing it to
foreach ($data as $k >= $v){
or
foreach ($data as $k > $v){

the error is in the greater than or equal condition.

you may also prefer to use
echo $k.":". $v ."\n";
than the
echo "$k: $v \n";

i hope this helps. Ϋ
good luck and happy day!

its not a greater or lesser statement.
it is supposed to be => (the arrow operator)
the problem is the $k and $v
read the manual on parse_url here
hopefully that helps :)

its not a greater or lesser statement.
it is supposed to be => (the arrow operator)
the problem is the $k and $v
read the manual on parse_url here
hopefully that helps :)

yeah. metalix is right. :$

well, now that i tried the same exact file, it worked just fine... with no modification made to it. I don't get it. could be that encoding used to save the file resulted in the Chinese. I tried saving a working file in different encoding, but I can't generate the Chinese producing version now. In any encoding other than ANSI, the script outputs nothing now. Anyways, thanks for trying.

yeah it's probably something blatently obvious that is doing it that noone can see :P
if its solved please mark as solved :)

well, it is not solved.. we still don't know what the problem was. but, I think I will mark it as solved anyways since I have the impression that hardly anyone will be able to explain it.

well, it is not solved.. we still don't know what the problem was. but, I think I will mark it as solved anyways since I have the impression that hardly anyone will be able to explain it.

negative impression ey?
there would be certainly someone who can explain that bug clearly.
besides IT is a world of possibilities. Ϋ

:)never loose hope man!

that's funny man... :) I still think I will just forget about it until I learn more basic stuff first.

that's funny man... :) I still think I will just forget about it until I learn more basic stuff first.

I'm really starting to be the "man".
now that's funny. Ϋ

anyway, good luck man.
:)

So is it solved? If not, can you give us a sample of some of the URL's you try? The URL you gave in the first post should work fine and did work fine when I tried it. If it doesn't, have you set your charset to the appropriate one with the meta charset tag?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.