943,866 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1523
  • PHP RSS
Nov 21st, 2007
0

replace string

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
michael123 is offline Offline
93 posts
since Jun 2005
Nov 22nd, 2007
0

Re: replace string

preg_replace()
Reputation Points: 28
Solved Threads: 71
Posting Pro
ryan_vietnow is offline Offline
578 posts
since Aug 2007
Nov 23rd, 2007
0

Re: replace string

Simple PHP should do it if you do not know regular expressions.

PHP Syntax (Toggle Plain Text)
  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;
Reputation Points: 15
Solved Threads: 5
Junior Poster in Training
TopDogger is offline Offline
87 posts
since Aug 2005
Nov 25th, 2007
0

Re: replace string

There are many ways, but i agree with top dogger, the above is the most simplest and works effectivly
Reputation Points: 12
Solved Threads: 16
Posting Whiz
Designer_101 is offline Offline
314 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Help with php and dreamweaver requested
Next Thread in PHP Forum Timeline: PHP blog from flat file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC