Page 1 of 1

array_values and array_keys doesnt like my array

Posted: Fri Jul 20, 2007 1:25 am
by toasty2
I'm making a HTML entity converter (letters and symbols, starting with entity #32) and both array_keys and array_values say I haven't passed them an array, code:

Code: Select all

<?php
$ents = array(
	' ',
	'!',
	'"',
	'#',
	'$',
	'%',
	'&',
	'\'',
	'(',
	')',
	'*',
	'+',
	',',
	'-',
	'.',
	'/',
	'0',
	'1',
	'2',
	'3',
	'4',
	'5',
	'6',
	'7',
	'8',
	'9',
	':',
	';',
	'<',
	'=',
	'>',
	'?',
	'@',
	'A',
	'B',
	'C',
	'D',
	'E',
	'F',
	'G',
	'H',
	'I',
	'J',
	'K',
	'L',
	'M',
	'N',
	'O',
	'P',
	'Q',
	'R',
	'S',
	'T',
	'U',
	'V',
	'W',
	'X',
	'Y',
	'Z',
	'[',
	'\\',
	']',
	'^',
	'_',
	'`',
	'a',
	'b',
	'c',
	'd',
	'e',
	'f',
	'g',
	'h',
	'i',
	'j',
	'k',
	'l',
	'm',
	'n',
	'o',
	'p',
	'q',
	'r',
	's',
	't',
	'u',
	'v',
	'w',
	'x',
	'y',
	'z',
	'{',
	'|',
	'}',
	'~'
);

function convertHTMLent($text)
{
	return str_replace(array_values($ents), '&#'.array_keys($ents)+32 .';', $text);
}
echo convertHTMLent('Hello');
?>
Error:

Code: Select all

Warning: array_values() [function.array-values]: The argument should be an array in X:\htdocs\tools\htmlent.php on line 102

Warning: array_keys() [function.array-keys]: The first argument should be an array in X:\htdocs\tools\htmlent.php on line 102
Hello

Posted: Fri Jul 20, 2007 1:51 am
by nickvd
Your homework for tonight is to read: http://ca.php.net/manual/en/language.va ... .scope.php