<?php
$rainbowmsg ="";
$var ="";
$scale="";
$out=array(' Ann',' james',' rejo mathew',' sjo d emmanual',' mary varghese','devan','benqb','riya');
$links=array(' Ann',' james',' rejo mathew',' sjo d emmanual',' mary varghese','devan','benqb','riya');
//color arrays
$rainbow = array('#C36546','#006633' , '#000099' , '#FF0000' , '#FF6699' , '#0099FF', '#FFFF00' , '#33FF00');
//get the message



	for( $j=0; $j<1; $j++ )
{
	foreach ($out as $value)
	{
  	 $var.= "<br/>".$value.","; 		  		
	}	
}

//print_r($links);
$out = $rainbow;
//split message into array 
$messagearr=explode(",",trim(chunk_split($var)));
$i = 0; //$i will keep count of which color in $colorarr we're up to
$max=count($out, COUNT_RECURSIVE);	
//$max = count($colorarr); //the total number of colors in $colorarr

//loop through $messagearr
foreach ($messagearr as $letter) {
  //if character isn't a space, assign color and add to $rainbowmsg:
  if ($letter != " ") {
  
  {
	
	$rainbowmsg .= "<a href=".trim($links[$i])."><font color=\"".$out[$i]."\">$letter</font></a>";

  }

  }
  //else add a space to $rainbowmsg:
  else { $rainbowmsg .= " "; }
  //+1 to $i (so that the next loop uses the next color in $colorarr):
  $i++;
  //if we've reached the end of $colorarr, set $i to zero to start again:
  if ($i == $max) { $i = 0; }
} //(end foreach loop)

//output the rainbow code:
echo "<div style='cursor:pointer'>".$rainbowmsg."</div>";

?>

When i run this code its working but when i click on "rejo mathew" the link only takes "rejo" and same as the array includes spaces in their name

Hi,

The problem is in the concatenation of the string with the double quotes in <a href>.
Replace the existing line 36 with this,

$rainbowmsg .= "<a href='".trim($links[$i])."'><font color=\"".$out[$i]."\">$letter</font></a>";

If you use the spaces between the values which is in array, use rawurldecode in php to work that values.

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.