Jump to content
xisto Community
souradipm

Help With Php! A question that needs an answer

Recommended Posts

Hey,
I am currently making a program with php and I need to know an answer - I need to know the wildcard for all.
It may sound stupid, I know it is *(asterisk) but does php support it?

if ($var="Sometext".*) {  //code here}
Will that work? Any other solutions?

Thanks in advance,
souradipm
Edited by souradipm (see edit history)

Share this post


Link to post
Share on other sites

What about testing this syntax on your own PC ?
You download "easy php" from http://www.easyphp.org/ , the installation lasts half a minute, and you have a working webserver with php, then you put your program in a subfoler of the "www" folder and you test it !
Of course, waiting for an answer in this forum may give a faster answer, however having a working testing environment is usually very interesting.
Regards
Yordan

Share this post


Link to post
Share on other sites

Thing is, my computer is a family PC and I don't want to turn it into a webserver. Also, this code is actually part of a larger program, making it so that I have to complete the program to actually test it out.~souradipm

Share this post


Link to post
Share on other sites

Unless someone knows better than me, I think the solution will require some pattern matching using a regular expression.

 

This will probably confuse you:

http://forums.xisto.com/no_longer_exists/

 

This is the example that best matches your situation:

http://us3.php.net/manual/en/function.preg-match.php

<?php// The "i" after the pattern delimiter indicates a case-insensitive searchif (preg_match("/php/i", "PHP is the web scripting language of choice.")) {   echo "A match was found.";} else {   echo "A match was not found.";}?> 

 

Of course, you'll need a reg_ex for your situation:

 

I think this will work for you:

 

"/sometext\.([^ ]*)/i"

All together:

if (preg_match("/sometext\.([^ ]*)/i", "sometext.html")) {   echo "A match was found.";}

This will match anything after "sometext." except a space! So "sometext.%$^%" is ok but "sometext. Hello" is not!

 

You should try to specify what the extention sould be.

Like any letter or number only would be:

"/sometext\.([A-Za-z0-9-]{1,})/i"
Which means match at least "1" of any upper or lower case letter or number.

The upside to that is that it will end at either a whitespace or some non-alpha-numeric character like a punctuation mark or special character.

 

If you want to specify that the extention is at least 3 characters long then use this:

"/sometext\.([A-Za-z0-9-]{3,})/i"

If you want more leadway on the size of the extention, you could specify between 2 and 4 characters like this:

"/sometext\.([A-Za-z0-9-]{2,4})/i"

For exactly 3 characters long only, use this:

"/sometext\.([A-Za-z0-9-]{3})/i"

I hope this helps. :D

 

vujsa

Share this post


Link to post
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

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.