RE: [PHP] replacing first occurence

2002-04-24 Thread Maxim Maletsky \(PHPBeginner.com\)


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   // where PHP Begins




-Original Message-
From: Diana Castillo [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, April 24, 2002 6:09 PM
To: [EMAIL PROTECTED]
Subject: [PHP] replacing first occurence


What function can I use to replace just the first occurence of a , in
a string? Thank you



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] replacing first occurence

2002-04-24 Thread Steve Bradwell

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 occurence of a , in a
string?
Thank you



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] replacing first occurence

2002-04-24 Thread Philip Olson


 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) {
  $str{$pos} = '!';
  }

  print $str;// Hello! I love you!';
  print $pos;// 5
  print $str{0}; // H
  print $str{5}; // !


Regards,
Philip Olson





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php