Bug or am I being dumb

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

Post Reply
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Bug or am I being dumb

Post by John Cartwright »

Code: Select all

function format2xml($xml) {
	$transaction = '<TRANSACTION>';
	foreach ($xml as $keyname => $value) {
		$transaction .= '<'.$keyname.'>'.$value.'</'.$keyname.'>';
	}
	$transaction .= '</TRANSACTION>';
	return $transaction;
}
Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to gt;';
foreach ($xml as $keyname => $value) {
$transaction .= '<'.$keyname.'>'.$value.'</'.$keyname.'&gt;';
}
$transaction .= '&lt;/TRANSACTION&gt;';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and all that will return is 'cart'
Same results as my function... :roll: I hANSACTION>';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '&a;amp;gt; $value) {
		$transaction .= '<'.$keyname.'>'.$value.'</'.$keyname.'>';
	}
	$transaction .= '</TRANSACTION>';
	return $transaction;
}
Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a lction = '<TRANSACTION>';
foreach ($xml as $keyname => $value) {
$transaction .= '<'.$keyname.'>'.$value.'</'.$keyname.'>';
}
$transaction .= '</TRANSACTION>';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '&ampfunction format2xml($xml) {
	$transaction = '<TRANSACTION>';
	foreach ($xml as $keyname => $value) {
		$transaction .= '<'.$keyname.'>'.$value.'</'.$keyname.'>';
	}
	$transaction .= '</TRANSACTION>';
	return $transaction;
}
Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</function format2xml($xml) {
	$transaction = '<TRANSACTION>';
	foreach ($xml as $keyname => $value) {
		$transaction .= '<'.$keyname.'>'.$value.'</'.$keyname.'>';
	}
	$transaction .= '</TRANSACTION>';
	return $transaction;
}
Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and all that will rech ($xml as $keyname => $value) {
$transaction .= '<'.$keyname.'>'.$value.'</'.$keyname.'>';
}
$transaction .= '</TRANSACTION>';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and all that will return is 'cart'
Same results as my function... :roll: I have no idea what's going on and have never encountered this. Any thoughts?

Edit| It returns the middle value 'cart' not 'jay'amp;gt; $value) {
$transaction .= '<'.$keyname.'&gt;'.$value.'&lt;/'.$keyname.'&gt;';
}
$transaction .= '</TRANSACTION>';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrl($xml) {
$transaction = '<TRANSACTION>';
foreach ($xml as $keyname => $value) {
$transaction .= '&lt;'.$keyname.'&gt;'.$value.'</'.$keyname.'>';
}
$transaction .= '</TRANSACTION>';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and]

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and all that will return is 'cart'
Same results as my function... :roll: I have no idea what's going on and have never encountered this. Any thoughts?

Edit| It returns the middle value 'cart' not 'jay'= '<TRANSACTION>';
foreach ($xml as $keyname =&gt; $value) {
$transaction .= '&lt;'.$keyname.'&gt;'.$value.'&lt;/'.$keyname.'&gt;';
}
$transaction .= '&lt;/TRANSACTION&gt;';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and all that will return is 'cart'
Same results as my function... :roll: I have no idea what's going on and have never encountered this. Any thoughts?

Edit| It returns the middle value 'cart' not 'jay'nsaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and all that will return is 'cart'
Same results as my function... :roll: I have no idea what's going on and have never encountered this. Any thoughts?

Edit| It returns the middle value 'cart' not 'jay' $transaction .= '<'.$keyname.'>'.$value.'</'.$keyname.'>';
}
$transaction .= '&lt;/TRANSACTION&gt;';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and all that will return is 'caTION>';
foreach ($xml as $keyname => $value) {
$transaction .= '&lt;'.$keyname.'&gt;'.$value.'&lt;/'.$keyname.'&gt;';
}
$transaction .= '&lt;/TRANSACTION&gt;';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and all that will return is 'cart'
Same results as my function... :function format2xml($xml) {
$transaction = '<TRANSACTION>';
foreach ($xml as $keyname => $value) {
$transaction .= '<'.$keyname.'>'.$value.'</'.$keyname.'>';
}
$transaction .= '</TRANSACTION>';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and all that will return is 'cart'
Same results as my function... :roll: I have no idea what's going on and have never encountered this. Any thoughts?

Edit| It returns the middle value 'cart' not 'jay't;TRANSACTION>';
foreach ($xml as $keyname => $value) {
$transaction .= '<'.$keyname.'>'.$value.'</'.$keyname.'&gt;';
}
$transaction .= '&lt;/TRANSACTION&gt;';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and all that will return is 'cart'
Same results as my function... :roll: I have no idea what's going on and have never encountered this. Any thoughts?

Edit| It returns the miamp;lt;/'.$keyname.'>';
}
$transaction .= '</TRANSACTION>';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and all that will return is 'cart'
Same results as my function... :roll: I have no idea what's going on and have never encountered this. Any thoughts?

Edit| It returns the middle value 'cart' not 'jay'function format2xml($xml) {
$transaction = '<TRANSACTION>';
foreach ($xml as $keyname => $value) {
$transaction .= '<'.$keyname.'>'.$value.'</'.$keyname.'>';
}
$transaction .= '</TRANSACTION>';
return $transaction;
}

Okay the array I pass to it is fine, but the < and > are disapeering and only the last $keyname is appearing in the string. Sort of a weird thing to happen. But I wrote a little test echo to see if I was just forgetting something in this function

Code: Select all

echo '<jay>cart</jay>';
and all that will return is 'cart'
Same results as my function... :roll: I have no idea what's going on and have never encountered this. Any thoughts?

Edit| It returns the middle value 'cart' not 'jay'
Last edited by John Cartwright on Wed Jul 06, 2005 11:03 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Huh? That's really weird :?

So if you tried to file_get_contents() a local HTML document and echo() the content (nothing else in that script) it would just display junk?

There's nothing wrong with the PHP code :?

EDIT | Or echo '<b>d11wtq</b>'; isn't bold?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

hrmm it seems taht when I look in the source it is

Code: Select all

<jay>cart</jay>
I guess it is returning the expected values.. my bad :roll: the browser was just trying to parse it... I guess it was me being st00pid.

Add me to the 'Finest moment Award'
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Jcart wrote:hrmm it seems taht when I look in the source it is

Code: Select all

<jay>cart</jay>
I guess it is returning the expected values.. my bad :roll: the browser was just trying to parse it... I guess it was me being st00pid.

Add me to the 'Finest moment Award'
Hahaha, I did wonder but didn't wanna ask (hence why I asked to do some valid HTML) :P Glad you worked it out ;)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Btw, you might want to run http://www.php.net/htmlentities on the values, to make sure the xml remains valid.... or use <![CDATA[ <html> ]]>...
Post Reply