Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8030015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:37:32+00:00 2026-06-05T00:37:32+00:00

I have a string like My String 2 and I like to get only

  • 0

I have a string like “My String 2” and I like to get only num value “2”.
I try to do that you see below but result is egal to 0.

$AlphaSURV1="My String 2";
$NumSURV1=intval($AlphaSURV1);
echo $NumSURV1;

Can you help me to solve that?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:37:34+00:00Added an answer on June 5, 2026 at 12:37 am

    In order to capture the last group of digits in a string, you can use a regular expression:

    $str = "123 test 29";
    preg_match("/[0-9]+$/", $str, $matches);
    var_dump($matches[0]); # 29
    

    This work correctly for all the following cases, including lack of whitespace, leading digits and multiple digits at the end of the string:

    "1"        => 1
    "test 2"   => 2
    "test 34"  => 34
    "5 test 6" => 6
    "7test8"   => 8
    

    Note that if you simply want to get the last character in the string and treat it like a number you can use the following:

    $str = "My String 2";
    
    $digit = intval(substr($str, -1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this. <p class='link'>try</p>bla bla</p> I want to get only
if I have a string like some/unknown/amount/of/sub/folder/file.txt how can I get only the the
I have a String like : name:lala,id:1234,phone:123 but for example I want to get
I have a string Like this: MyText (1,151) I would like to get with
I have a string in C# and would like to get text from specific
I have a string 2010-08-02 12:13:06.0 and need to get something like Fri Aug
I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string
Suppose I have a Dictionary like so: Dictionary<string, Stream> How can I get a
Let's presume that I have string like '=&?/;#+%' to be a part of my
i have a string that looks like this apples,fish,oranges,bananas,fish i want to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.