/    Sign up×
Community /Pin to ProfileBookmark

Parsing a String – I need the last few characters only. How?

I have a string, let’s say:

[QUOTE]

This is string #4455

[/QUOTE]

I want to take this string and only show the “4455” at the end. Is there any way I can cut this string from the end until it touches the # sign? I suppose you can say I’m using the octothorpe as my delimiter. How would I do this?

Thanks.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@thraddashDec 17.2009 — There are multiple ways you can approach this:

[code=php]$string = 'This is string #4455';
echo $string . '<br />';

//REGULAR EXPRESSION
if (preg_match('/(d+)$/', $string, $matches)) {
echo $matches[1] . '<br />';
}

//SPLITTING
$parts = explode('#', $string);
echo array_pop($parts);[/code]
Copy linkTweet thisAlerts:
@chris22Dec 17.2009 — hi, you can do it this way:

[code=php]
$str = "This is string #4455";

$digits = substr($str,strpos($str,'#'));

[/code]
Copy linkTweet thisAlerts:
@multimediocrityauthorDec 18.2009 — Thanks!! Got it! ?
×

Success!

Help @multimediocrity spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...