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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:39:14+00:00 2026-05-31T18:39:14+00:00

I will make this quick and simple I have a query and I want

  • 0

I will make this quick and simple

I have a query and I want to split it so that it returns an array with words after the : symbol. This is what I have so far and it does as expected but returns the whole string before the matched needle. I just want the array to contain words after the : symbol.

<?php  $arr = preg_split('/[:]/', $query, 0); 

   print_r($arr);

 ?>

This returns

    Array
(
    [0] => SELECT user_name FROM test WHERE user_name = 
    [1] => user_name
)

using this query

“SELECT user_name FROM test WHERE user_name = :user_name”

thanks for any help

  • 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-31T18:39:16+00:00Added an answer on May 31, 2026 at 6:39 pm

    Try this:

    preg_match_all("/:(\w+)/", $string, $matches);
    

    By doing this, all your elements that are after a : will be in $matches[1] sub-array. I’m assuming you want to handle SQL statements with multiple named parameters. So for example:

    SELECT user_name FROM test WHERE user_name = :user_name and last_name = :last_name
    

    Will result in $matches being:

    array(2) {
      [0]=>
      array(2) {
        [0]=>
        string(10) ":user_name"
        [1]=>
        string(10) ":last_name"
      }
      [1]=>
      array(2) {
        [0]=>
        string(9) "user_name"
        [1]=>
        string(9) "last_name"
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will try to make this simple and quick.. I have never attempted this
How do you sort an array of strings in C++ that will make this
Just after a quick wait command that will make my application stop, for say
I will make this quick. I'm using Ruby/LDAP to search using my base_dn criteria.
I'm fairly new to C# but I will try to make this quick! ;)
Ho to make this simple xml with php using DOM? Full code will be
How can i make an extension method that will work like this public static
I'm trying to make a notification area that will show alerts. return this.each(function() {
I'll try and make this quick: I've an external class that parses the JSON
Hopefully this will be one of those simple answers that is so simple they

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.