replace string

Reply

Join Date: Jun 2005
Posts: 92
Reputation: michael123 is an unknown quantity at this point 
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

replace string

 
0
  #1
Nov 21st, 2007
how can I replace who string with certain beginning and ending, for example I have string:
abc........xyz

I want to replace this string with "this is a test", no matter what text in between, only "abc" and "xyz" are fixed.

abc123xyz-->this is a test
abcd1234xyz-->this is a test

any idea?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 569
Reputation: ryan_vietnow is an unknown quantity at this point 
Solved Threads: 71
ryan_vietnow's Avatar
ryan_vietnow ryan_vietnow is offline Offline
Posting Pro

Re: replace string

 
0
  #2
Nov 22nd, 2007
preg_replace()
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 87
Reputation: TopDogger is an unknown quantity at this point 
Solved Threads: 5
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

Re: replace string

 
0
  #3
Nov 23rd, 2007
Simple PHP should do it if you do not know regular expressions.

  1. $string = "abcd123xyz";
  2.  
  3. if((substr($string,0,3)=="abc") && (substr($string,-3)=="xyz"))
  4. {
  5. $string = "this is a test";
  6. }
  7.  
  8. echo $string;
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 258
Reputation: Designer_101 is an unknown quantity at this point 
Solved Threads: 12
Designer_101's Avatar
Designer_101 Designer_101 is offline Offline
Posting Whiz in Training

Re: replace string

 
0
  #4
Nov 25th, 2007
There are many ways, but i agree with top dogger, the above is the most simplest and works effectivly
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC