|
|
|
|
![]() ![]() |
Aug 19 2006, 04:17 PM
Post
#1
|
|
|
Member [ Level 1 ] Group: Members Posts: 42 Joined: 17-July 06 Member No.: 14,552 |
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? CODE if ($var="Sometext".*) { //code here } Will that work? Any other solutions? Thanks in advance, souradipm This post has been edited by souradipm: Aug 19 2006, 04:18 PM |
|
|
|
Aug 19 2006, 04:26 PM
Post
#2
|
|
|
Way Out Of Control - You need a life :) Group: [MODERATOR] Posts: 2,193 Joined: 16-August 05 Member No.: 7,896 myCENTs:54.04 |
What about testing this syntax on your own PC ?
You download "easy php" from http://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 |
|
|
|
Aug 19 2006, 04:30 PM
Post
#3
|
|
|
Member [ Level 1 ] Group: Members Posts: 42 Joined: 17-July 06 Member No.: 14,552 |
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 |
|
|
|
Aug 20 2006, 06:58 AM
Post
#4
|
|
|
Absolute Newbie Group: Admin Posts: 888 Joined: 20-February 05 From: Indianapolis, Indiana, USA (Midwest) Member No.: 2,714 myCENTs:35.43 |
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://us3.php.net/manual/en/reference.pcr...tern.syntax.php This is the example that best matches your situation: http://us3.php.net/manual/en/function.preg-match.php QUOTE(http://us3.php.net/manual/en/function.preg-match.php) CODE <?php // The "i" after the pattern delimiter indicates a case-insensitive search if (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: CODE "/sometext\.([^ ]*)/i" All together: CODE 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: CODE "/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: CODE "/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: CODE "/sometext\.([A-Za-z0-9-]{2,4})/i" For exactly 3 characters long only, use this: CODE "/sometext\.([A-Za-z0-9-]{3})/i" I hope this helps. vujsa |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 23rd November 2008 - 04:56 PM |