looping through text with array_key_exists function



Hi,

I'm having a major headache with what I expected to be a simple
problem, which is to take a string of text, split it down to an array
of individual characters (including spaces), then cycle through the
array and create HTML which assigns specific images to the characters -
i.e. 'a' will be replaced by '<img src="a.jpg"'>, etc....

However, if I pass a string to the following function (such as "John
James Smith"), it goes so far, then stops converting the letters to
images. I suspect that it has something to do with the foreach loop
encountering spaces ?

Not exactly sure what could be going on here, and how to move forwards.

Any suggestions ?

Thanks
Neil.


code below
------------------------------------

function convert_text_to_images($text) {


$split = preg_split('//', strtolower($text), -1, PREG_SPLIT_NO_EMPTY);



$convert = array("a" => "a.jpg", "b" => "b.jpg", "c" => "c.jpg", "d" =>
"d.jpg", "e" => "e.jpg", "f" => "f.jpg", "g" => "g.jpg", "h" =>
"h.jpg", "i" => "i.jpg", "j" => "j.jpg", "k" => "k.jpg", "l" =>
"l.jpg", "m" => "m.jpg", "n" => "n.jpg", "o" => "o.jpg", "p" =>
"p.jpg", "q" => "q.jpg", "r" => "r.jpg", "s" => "s.jpg", "t" =>
"t.jpg", "u" => "u.jpg", "v" => "v.jpg", "w" => "w.jpg", "x" =>
"x.jpg", "y" => "y.jpg", "z" => "z.jpg", "0" => "0.jpg", "1" =>
"1.jpg", "2" => "2.jpg", "3" => "3.jpg", "4" => "4.jpg", "5" =>
"5.jpg", "6" => "6.jpg", "7" => "7.jpg", "8" => "8.jpg", "9" =>
"9.jpg");


$imgsrc_string="";

foreach($split as $key=>$value){

if(array_key_exists($key, $convert)){$imgsrc_string .= '<img
src="'.$convert[$value].'" alt="'.$value.'">'; }
elseif ($value == ' ') {$imgsrc_string .= '<img src="space.jpg"
alt="&nbsp;">';}
else {$imgsrc_string .= $value;}

}
return($imgsrc_string);
}

.



Relevant Pages

  • Re: Loading image in Orca/Pascal
    ... necessary to load images using Orca - again, ... Also required is the P2GSString to convert the Pascal string into a GS/ ... if ToolError = 0 then begin ... srcHdl:= NewHandle(srcSize, ...
    (comp.sys.apple2.programmer)
  • Re: How to reference a Table in a Sub procedure
    ... If you have a table named Images in the current db then "SELECT * FROM ... make sure you assign your sql string to a variable: ... completed strSQL. ... figured out how passing the variables to the sub procedure works ...
    (microsoft.public.access.formscoding)
  • Re: storing path only to database
    ... is about 5gb..the type of file that i have to store is images ... cannot store all the images because of the limitation...now...i want to ... Dim MyFolder As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: how to set background of TD without an ID to none
    ... So whatever is assigned to the document.body.background attribute must be a string. ... table cell, but nothing instead, or second option, a transparent gif ... document.write which does something with images messes it up, ... happyimages = el.getElementsByTagName; ...
    (comp.lang.javascript)
  • Re: SqlDataReader.GetBytes Results in an System.InvalidCastExcepti
    ... For the bytes arrays you need a memorystreem to convert them to images ... private void SqlBlob2File(string DestFilePath, string id) ... SqlCommand cmd = new SqlCommand("SELECT Body FROM ActivityMimeAttachment ... > added two fields ID as a UID and MyText of type Text. ...
    (microsoft.public.dotnet.framework.adonet)