HOME       >>       Programming

Help With Php! A question that needs an answer


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,


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.


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


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


This will probably confuse you:



This is the example that best matches your situation:


<?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:

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:


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


For exactly 3 characters long only, use this:


I hope this helps.




Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.