Page 1 of 1

udt - include_once - tricky problem

Posted: Wed Sep 26, 2007 10:31 am
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

Re: udt - include_once - tricky problem

Posted: Wed Sep 26, 2007 3:11 pm
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 ;).