开发者

sub string replacment in PHP

I have a string like: $string = "/physics/mechanics/vectors/P-M-C (1).doc";

I want to get like this:

"/physics/mechanics/vectors/1-P-M-C (1).doc";

Please note that "1-" is added just before P in the original string.

Is it possible in PHP? How the function in PHP should be us开发者_运维知识库ed?


@fawad:Here's a sample to get you started --

$oldstring = "/physics/mechanics/vectors/P-M-C (1).doc";
$parts = explode("/", $oldstring);
$file = $parts[count($parts) - 1];

$newstring = str_replace($file, "1-" . $file, $oldstring);


Take a look at explode() and join() for this. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜