this is the code below it output the text randamly. i am getting the output . but my problem is i have used print_r to get output
so i got result as

<Array ( [0] => gello [1] => bello [2] => nello [3] => jello [4] => uello [5] => yello [6] => hwllo [7] => hsllo [8] => hdllo [9] => hrllo [10] => h4llo [11] => h3llo [12] => heklo [13] => heplo [14] => heolo [15] => helko [16] => helpo [17] => heloo [18] => helli [19] => hellk [20] => helll [21] => hellp [22] => hell0 [23] => hell9 )

but want
gello
bello
nello like this

any body help how to conver an array to normal words without array[0] ext

<?
$word = "Hello";
$typos = array();
$typos = cTypoGenerator::getWrongKey( $word );



   print_r ($typos);





class cTypoGenerator
{

// array of keys near character on a QWERTY keyboard
// only valid characters in a domain name
	static $keyboard = array(
// top row
		'1' => array( '2', 'q' ),
		'2' => array( '1', 'q', 'w', '3' ),
		'3' => array( '2', 'w', 'e', '4' ),
		'4' => array( '3', 'e', 'r', '5' ),
		'5' => array( '4', 'r', 't', '6' ),
		'6' => array( '5', 't', 'y', '7' ),
		'7' => array( '6', 'y', 'u', '8' ),
		'8' => array( '7', 'u', 'i', '9' ),
		'9' => array( '8', 'i', 'o', '0' ),
		'0' => array( '9', 'o', 'p', '-' ),
		'-' => array( '0', 'p' ),
// 2nd from top
		'q' => array( '1', '2', 'w', 'a' ),
		'w' => array( 'q', 'a', 's', 'e', '3', '2' ),
		'e' => array( 'w', 's', 'd', 'r', '4', '3' ),
		'r' => array( 'e', 'd', 'f', 't', '5', '4' ),
		't' => array( 'r', 'f', 'g', 'y', '6', '5' ),	
		'y' => array( 't', 'g', 'h', 'u', '7', '6' ),
		'u' => array( 'y', 'h', 'j', 'i', '8', '7' ),
		'i' => array( 'u', 'j', 'k', 'o', '9', '8' ),
		'o' => array( 'i', 'k', 'l', 'p', '0', '9' ),
		'p' => array( 'o', 'l', '-', '0' ),
// home row
		'a' => array( 'z', 's' , 'w', 'q' ),
		's' => array( 'a', 'z', 'x', 'd', 'e', 'w' ),
		'd' => array( 's', 'x', 'c', 'f', 'r', 'e' ),
		'f' => array( 'd', 'c', 'v', 'g', 't', 'r' ),
		'g' => array( 'f', 'v', 'b', 'h', 'y', 't' ),
		'h' => array( 'g', 'b', 'n', 'j', 'u', 'y' ),
		'j' => array( 'h', 'n', 'm', 'k', 'i', 'u' ),
		'k' => array( 'j', 'm', 'l', 'o', 'i' ),
		'l' => array( 'k', 'p', 'o' ),
// bottom row
		'z' => array( 'x', 's', 'a' ),
		'x' => array( 'z', 'c', 'd', 's' ),
		'c' => array( 'x', 'v', 'f', 'd' ),
		'v' => array( 'c', 'b', 'g', 'f' ),
		'b' => array( 'v', 'n', 'h', 'g' ),
		'n' => array( 'b', 'm', 'j', 'h' ),
		'm' => array( 'n', 'k', 'j' )
	);




	function getWrongKey( $word )
	{
		$word = strtolower( $word );
		$typos = array();
		$length = strlen( $word );
// check each character
		for( $i = 0; $i < $length; $i++ )
		{
// if character has replacements then create all replacements
			if( cTypoGenerator::$keyboard[$word{$i}] )
			{
// temp word for manipulating
				$tempWord = $word;
				foreach( cTypoGenerator::$keyboard[$word{$i}] as $char )
				{
					$tempWord{$i} = $char;			
					array_push( $typos, $tempWord );
				}
			}
		}

		return $typos;
	}

Recommended Answers

All 3 Replies

You cannot access elements of an array without using the square brackets, in general. That's what an array IS, a collection of elements, and you access them via the proper key, delimited by square brackets.

You can implode an array into a single delimited array, but then you'd have to do a split to get your "normal words"... but they'd be an array of substrings, so you're back to using square brackets.

I guess I don't understand the question... what would your "normal words" look like, in terms of variables?

The function that outputs the array in the example you've given is:

print_r ($typos);

There are a number of ways to output in the manner in which you require, and most will use a loop of some kind. As a starter for 10, try outputting with a foreach statement:

foreach($typos as $key) { echo "$key\n"; }

The function that outputs the array in the example you've given is:

print_r ($typos);

There are a number of ways to output in the manner in which you require, and most will use a loop of some kind. As a starter for 10, try outputting with a foreach statement:

foreach($typos as $key) { echo "$key\n"; }

thank you so much it worked.

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.