Jump to content

wild card search key for php


Recommended Posts

I have been trying to find the wild card search key for php.

Remember back in dose if you did a dir images*.jpg, it would return all files named imagesXX.jpg

I need to do something similar in php.

Anyone know what the wild card is?

Link to comment
Share on other sites


that would be so helpful. how about wild cards like when you start typing a word in and before you finish typing it, results are already showing up.

like if you want to type "car" and youve only typed in "ca" so for, it would show "cat, car, cap, etc..."

Link to comment
Share on other sites

The wildcard in Regular Expression (used in functions like preg_match or preg_replace) would be a simple 'period'.

Lets say you're seraching inside 'My dog is a lazy dog';

'.' = Matches any single character

Would match 'M'

'.*' = Matches everything till the very end (greedy)

Would match 'My dog is a lazy dog' (since no other match at end was indicated).

However...

'.*g' Would match 'My dog is a lazy dog' Since 'g' is the very last end match.

'.*?' = Matches till it hits the first match (lazy)

Would match 'My dog is a lazy dog' (since no other match at end was indicated).

However...

'.*?g' Would match 'My dog' due to 'g' being the first match of 'g'

To further note:

following a wildcard/match query with '*' means infinite matches till the end

following a wildcard/match query with '?' means match till the first matching text

following a wildcard/match query with '+' means it must match one or more times

If this wasn't very clear - the php manual has more info regarding regular expressions.

http://php.net/regex

As well as these other sites:

http://weblogtoolscollection.com/regex/regex.php

http://www.regular-expressions.info/php.html

Edited by Chozo4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...