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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:59:40+00:00 2026-05-31T21:59:40+00:00

I need to be able to search within a string and find out if

  • 0

I need to be able to search within a string and find out if [topic] is equal to a number and grab that number only from within the string.

For example, a string like so:

[topic]=10[board]=1

should return 10

But a string like this:

[topic][board]=1

should return 0 or false

A string like this:

[topic]=1.5[board]=2

should return 1, cause we need to round down floor()

Also, we aren’t worried about negative numbers, cause this will never happen.

How can I do this to just grab the number only, rounding down, from these types of strings that look like this, only if [topic] is present in the string and defined with an equal sign.

Thanks guys 🙂

  • 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-31T21:59:41+00:00Added an answer on May 31, 2026 at 9:59 pm

    The idea below uses preg_match and a regular express that looks for the word "topic" inside square brackets followed by an equal sign and one of more numbers. Before the matches, I set the default value of the topic (false in this case). If a topic is found, I then convert it to an integer.

    This will ignore the decimal point and any numbers that follow as \d only contains the numbers 0 through 9.

    Example:

    <?php 
    
    $string = '[topic]=10[board]=1';
    
    $topic = false;
    if (preg_match('/\[topic\]=(?P<topic>\d+)/', $string, $matches)) {
        $topic = (int)$matches['topic'];
    }
    
    var_dump($topic);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that I need to be able to search a file
I need to be able to remove the description text within search results which
I need to be able to search for text in a large number of
For an assignment I need to create a class within class Point from java.awt.Point.
So I have 3 entities within one table. I need to be able to
I have a search function within my program that looks for the name or
I want to be able to search within the commit logs of svn. I
I want to be able to search within the commit logs of svn. I
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to

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.