954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

replace string

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?

michael123
Junior Poster in Training
94 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

preg_replace()

ryan_vietnow
Posting Pro
578 posts since Aug 2007
Reputation Points: 28
Solved Threads: 71
 

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

$string = "abcd123xyz";

if((substr($string,0,3)=="abc") && (substr($string,-3)=="xyz"))
{
  $string = "this is a test";
}

echo $string;
TopDogger
Junior Poster in Training
87 posts since Aug 2005
Reputation Points: 15
Solved Threads: 5
 

There are many ways, but i agree with top dogger, the above is the most simplest and works effectivly :D

Designer_101
Posting Whiz
314 posts since Jul 2007
Reputation Points: 12
Solved Threads: 16
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You