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

  • Home
  • SEARCH
  • 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 8236911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:17:23+00:00 2026-06-07T19:17:23+00:00

i have this: preg_replace(‘/(\d{1}|\d{2})/gi’, ‘$1’, ‘some number’); If text is one digit number $1

  • 0

i have this:

preg_replace('/(\d{1}|\d{2})/gi', '$1', 'some number');

If text is one digit number $1 returns one digit number, if it is 2 digit it return 2 digit number…., but I need to returned number was always been 2 digit:

1 => 01 
2 => 02
...
10 => 10
...
99 => 99

How can I do that?

  • 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-07T19:17:25+00:00Added an answer on June 7, 2026 at 7:17 pm

    You mean like this one?use e modifier,execute php codes with preg_replace function,and whatever str_pad or sprintf would meet your requirement.

    preg_replace('/(\d{1}|\d{2})/ie', 'sprintf("%02d",$1)', 'some number');

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have found this: $text = preg_replace('/\W+/', '-', $text); Anyone can tell me what
I have this function to parse bbcode -> html: $this->text = preg_replace(array( '/\[b\](.*?)\[\/b\]/ms', '/\[i\](.*?)\[\/i\]/ms',
I currently have this regex: $text = preg_replace(#<sup>(?:(?!</?sup).)*$key(?:(?!</?sup).)*<\/sup>#is, '<sup>'.$val.'</sup>', $text); The objective of the
Ok, I have this regex here: $text = preg_replace('/\{\$(\w+)\}/e', '$params[$1]', $text); $params = an
I have this code: $text = '[iframe=200x200]http://stackoverflow.com[iframe] '; $text = preg_replace( '/\[iframe=(.*?)x(.*?)\](.*?)\[\/iframe\]/ms', '<iframe style=border:
I have this so far: preg_replace(([^\.\?\!]NNNNNNNNNN)[\.\?\!],,$string); and I also tried preg_replace(([^\.\?\!]\N\N\N\N\N\N\N\N\N\N)[\.\?\!],,$string); But it's removing
I need to replace all words with desired number of chars: Have this string:
we have this code: $value = preg_replace(/[^\w]/, '', $value); where $value is in utf-8.
currently, this is the preg_replace string that I have. $mtg_post['post_content'] = preg_replace([^\\x20-\\x7e], ,$ability); This
I have this code and I need to remove dot (.) only after TLD

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.