Page 1 of 1

some php advice needed for string replacement

Posted: Fri 15. Jun 2007, 21:26
by update
EDIT (did a wrong description of the problem)

Hi,
I want to rewrite a string
my-new-domain.tld
into
my_new_domain_tld
Now when I do
str_replace(".","_", $domain);
only "." are changed into "_" but I have to replace "-" --> "_" (if any) too
Now I'm stuck (didn't buy a book until now and still am now php wizard ) :wink:
Perhaps someone of the more advaned ones could show me the way? This would be great and 8)
Thank you!

Greetings
claus

Re: some php advice needed for string replacement

Posted: Sat 16. Jun 2007, 00:39
by pepe
maybe such a construct:

.
.
$domain1 = str_replace(".","_", $domain);
$domain = str_replace("-","_", $domain1);
.
.

Posted: Sat 16. Jun 2007, 00:47
by Jensensen
Hi claus,

schon mal versucht:

Code: Select all

$badchr		= array("-", ".");
$goodchr	  = array('_', '_');
       
str_replace($badchr, $goodchr, $domain);
greetz

Posted: Sat 16. Jun 2007, 20:46
by update
Danke!
Ja, das hatte ich nachts auch schon überlegt und vorhin alle Vorschläge ausprobiert, leider ohne Erfolg. Dies liegt augenscheinlich aber nicht mehr an dem str_replace, sondern an anderen (Datenbank-)Ungereimtheiten -
ich forsche weiter. Ist ja mächtig spannend!
Gruss
claus

Posted: Tue 19. Jun 2007, 16:00
by update
ich hab's jetzt so gemacht:

Code: Select all

list($dom, $rd) = explode('.',$domain);
$dom = str_replace(array('.','-'),"_", $dom);
Ob das so super elegant oder gar alles richtig ist, weiss ich nicht, aber es tutet
Danke noch mal für Eure Mühe
Gruss
claus