Two ways:
1. $string = preg_replace(^.{1}, 'h', 'bill'); // will make
'h'ill out of 'b'ill
2. $string = 'h'.substr('bill', 1);// will
get rid of the first char and concatenate
Sincerely,
Maxim Maletsky
Founder, Chief Developer
www.PHPBeginner.com //
http://www.php.net/manual/en/function.ereg-replace.php
-Steve.
-Original Message-
From: Diana Castillo [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 24, 2002 12:09 PM
To: [EMAIL PROTECTED]
Subject: [PHP] replacing first occurence
What function can I use to replace just the first
What function can I use to replace just the first occurence
of a , in a string?
Let's replace the first , with a ! and if , does
not exist at all let's not replace anything. Change
according to taste:
$str = 'Hello, I love you!';
if (($pos = strpos($str, ',')) !== false) {
3 matches
Mail list logo