get a substring

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

get a substring

Post by yaron »

hello all,
I have a string which has a number in it.
What I need is the substring that comes after the number.

for example:
hello-99goodbye.txt
I need to output => goodbye.txt
I'm guessing it's perl but I'm quite new at this.
Thank you all.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php
$text = 'hello-99goodbye.txt';
if (preg_match('!\d+(.*)$!', $text, $match))
	echo $match[1];
else
	echo 'no match';
?>
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

Yes, perl comes in handy sometimes :D

Code: Select all

$array = preg_split("|[\d]+|",$text);
// the last element in that array should be the goodbye.txt
I guess that will work.
Post Reply