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 7560039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:47:39+00:00 2026-05-30T12:47:39+00:00

I have a get url input which I need to pass it into databse,

  • 0

I have a get url input which I need to pass it into databse, but before doing that since I know that the user id would always be an integer number, I wanted to filter out everything but number in php. The follwoing code is what I came up with, does anyone know a better way than this? or is this the right way?

$id = preg_replace('#[^0-9]#i', '', $_GET['id']);
  • 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-05-30T12:47:41+00:00Added an answer on May 30, 2026 at 12:47 pm

    No.

    The carat (^) inside means NOT. I.E. not a character between 0 to 9 inclusive. We need to remove that. Also, i means that the regex is case insensitive; we don’t need to worry about that because numbers don’t have cases like other characters.

    We need to select what want part we’d like to keep. Brackets are used for this. The second parameter needs to contain a reference to the part we’d like to replace the string with (before storing in $id). So the whole function call would look like this:

    $id = preg_replace('#([0-9]+)#', '\1', $_GET['id']);
    

    + just implies that there will be multiple digits.

    You could then use is_int() to ensure that the result of the function call is in fact an INT, because if the function found no digit it will just return the value of $_GET['id'].

    $id = preg_replace('#([0-9]+)#', '\1', $_GET['id']);
    if(is_int($id))
    {
        //insert to DB
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery AJAX call with type:'GET' like this: $.ajax({type:'GET',url:'/createUser',data:userId=12345&userName=test, success:function(data){ alert('successful'); }
Suppose I was given a URL. It might already have GET parameters (e.g. http://example.com/search?q=question
I have the following code making a GET request on a URL: $('#searchButton').click(function() {
I have some source code to get the file name of an url for
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
I want to get only the headers of an URL request. I have been
So I have a class that has the following member variables. I have get
I've working on parsing an input, which is HTML. However, I need to be
I have a Drupal website that has a page at the URL alias of
I have an app that runs a process which needs to open an internet

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.