udt - include_once - tricky problem

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
crisb

udt - include_once - tricky problem

Post by crisb »

hi folks.

ok, here is one tricky question.
i have written the following udt (this is an excerpt, there is more in it):

Code: Select all

function begriff_to_include($begriff) {

    $d1 = array("ä" , "ö", "ü", "ß", "Ä", "Ö", "Ü", "é", "ó", "í", "ú", "á", " ", "," );
    $d2 = array("ae" , "oe", "ue", "ss", "Ae", "Oe", "Ue", "e", "o", "i", "u", "a", "-", "");

    $begriff_n = str_replace($d1, $d2, $begriff);
    $begriff_n = strtolower($begriff_n);
    return $begriff_n;
}

$title = $params['begriff'];
echo $title;
$dest = begriff_to_include($title);
echo $dest;
the udt is called like that {udtname begriff='Acné'} (for example).
what it does is pretty straight forward. it converts the word "Acné" to "acne". works like a charm so far.
but i want to use that udt more than once in a page. as it is right now i will get an error because the function begriff_to_include() gets redeclared. so i thought about including the function like that:

Code: Select all

include_once ("uploads/inc/functions.php");
but what happens now is that the word "Acné" gets converted to "acné". which means that the strtolower ist working, but the str_replace is not. you can test it out by yourself :-)

i have no clue why it behaves like that. so i will be really thankful if someone has an answer to this.

cheers,
chris
Last edited by crisb on Wed Sep 26, 2007 11:04 am, edited 1 time in total.
cyberman

Re: udt - include_once - tricky problem

Post by cyberman »

Try to put this in the udt

Code: Select all

$title = $params['begriff'];

$d1 = array("ä" , "ö", "ü", "ß", "Ä", "Ö", "Ü", "é", "ó", "í", "ú", "á", " ", "," );
$d2 = array("ae" , "oe", "ue", "ss", "Ae", "Oe", "Ue", "e", "o", "i", "u", "a", "-", "");

$begriff_n = str_replace($d1, $d2, $title);
$begriff_n = strtolower($begriff_n);

echo $title;
echo $begriff_n;
Works for me more than one time on the same page.

PS: An UDT is used like a Smarty function ;).
Locked

Return to “CMSMS Core”