Re: generating dynamic heading images
- From: "Dan Fulbright" <dfulbright@xxxxxxxxx>
- Date: 23 Jun 2005 09:43:54 -0700
> Ok, I have something working now, but with a few problems, my code is
> below:
>
> <?
> // 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;
> ?>
You could do away with your arrays by using backreferences and
preg_replace:
$final = preg_replace('/([a-zA-Z])/', '<img src="$1.gif" />', $string);
You would have to adjust things to work with spaces and other special
characters, but this would work with any letter.
--df
.
- References:
- generating dynamic heading images
- From: duncan . lovett
- Re: generating dynamic heading images
- From: Dan Fulbright
- Re: generating dynamic heading images
- From: duncan . lovett
- generating dynamic heading images
- Prev by Date: Re: php in ".html" documents
- Next by Date: Re: Authentication with sessions...
- Previous by thread: Re: generating dynamic heading images
- Next by thread: Re: generating dynamic heading images
- Index(es):
Relevant Pages
|
Loading