Sort of Dynamic Image generation - Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • duncan.lovett@litho.co.uk

    Sort of Dynamic Image generation - Problem

    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_replac e" 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

  • Ivan Omelchenko 608308824

    #2
    Re: Sort of Dynamic Image generation - Problem

    duncan.lovett@l itho.co.uk ÐÉÛÅÔ:[color=blue]
    > 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_replac e" 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
    >[/color]
    hows about preg_replace instead of str_replace ?

    Comment

    Working...