By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,727 Members | 766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,727 IT Pros & Developers. It's quick & easy.

Sort of Dynamic Image generation - Problem

P: n/a
I am working on a graphical heading generator for a clients website as
their server does not have the GD library or similar plugins for
dynamic image generation.

I have achieved the result partly, from a snipet I found in the user
contributions to the "str_replace" function in the manual on php.net.

However there is a small problem - it only works in uppercase. Please
first see my code below and then a brief description of the problem:
<?
// create a string ..
$txt = "My String Here";
$txt = strtoupper($txt);
// characters to search for
$txts = array ( "A", "B", "C", "D", "E", "F", and so forth );
// images array to replace them with.
$images = array ( "<img src=\"a.gif\" />", "<img src=\"b.gif\" />" ,
"<img src=\"c.gif\" />" , etc );
// continue with the <img src>'s with the number pattern above.
// Now, using str_replace to complete all the replacing.
$final = str_replace ($txts, $images, $txt);
echo $final;
?>
This works fine for my purpose, but, you will notice, I have to convert
my string to upper case characters for it to work.

If the string is in lower case, the str_replace function will replace
all the characters in the $images array as well.

Does anyone know a work around for this, so that i can use lower case
AND upper case characters?
Thanks,
DL

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
du***********@litho.co.uk пишет:
I am working on a graphical heading generator for a clients website as
their server does not have the GD library or similar plugins for
dynamic image generation.

I have achieved the result partly, from a snipet I found in the user
contributions to the "str_replace" function in the manual on php.net.

However there is a small problem - it only works in uppercase. Please
first see my code below and then a brief description of the problem:
<?
// create a string ..
$txt = "My String Here";
$txt = strtoupper($txt);
// characters to search for
$txts = array ( "A", "B", "C", "D", "E", "F", and so forth );
// images array to replace them with.
$images = array ( "<img src=\"a.gif\" />", "<img src=\"b.gif\" />" ,
"<img src=\"c.gif\" />" , etc );
// continue with the <img src>'s with the number pattern above.
// Now, using str_replace to complete all the replacing.
$final = str_replace ($txts, $images, $txt);
echo $final;
?>
This works fine for my purpose, but, you will notice, I have to convert
my string to upper case characters for it to work.

If the string is in lower case, the str_replace function will replace
all the characters in the $images array as well.

Does anyone know a work around for this, so that i can use lower case
AND upper case characters?
Thanks,
DL

hows about preg_replace instead of str_replace ?
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.