Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Help With Php!, A question that needs an answer!
souradipm
post Aug 19 2006, 04:17 PM
Post #1


Member [ Level 1 ]
Group Icon

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
Go to the top of the page
 
+Quote Post
yordan
post Aug 19 2006, 04:26 PM
Post #2


Way Out Of Control - You need a life :)
Group Icon

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
Go to the top of the page
 
+Quote Post
souradipm
post Aug 19 2006, 04:30 PM
Post #3


Member [ Level 1 ]
Group Icon

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
Go to the top of the page
 
+Quote Post
vujsa
post Aug 20 2006, 06:58 AM
Post #4


Absolute Newbie
Group Icon

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. cool.gif

vujsa
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Ask An Open Question 404 (and A Confused Noob)(3)
  2. Question Related To Website(5)
  3. Concept Of Hijaab In Islaam(2)
  4. Pointers(0)
  5. What's The Best CMS(38)
  6. Question: Ssh Tunneling(1)
  7. Do Google Search Better Than Yahoo?(15)
  8. Simple Java Question(3)
  9. Css Minus The <p>(9)
  10. MySQL Output Database Question(18)
  11. Mp3 Questions(14)
  12. Question About Opengl Codes.(0)
  13. How To Install Applications In Fedora(12)
  14. Ipod Hardware And Software Question(9)
  15. Question About Professional 3d Animating(21)
  1. VB.NET / MS Access Question(6)
  2. Php Question, Help Please(5)
  3. Private Servers Question(13)
  4. Question About Asp Now() Function(6)
  5. Joomla License Question(1)
  6. Dynamic Php Image And Better Php Code Question(10)
  7. Ever Needs To Find Out A Table Height Or With With JavaScript(2)
  8. Web Browser And Taskbar Problems (web Browser Disappears)(7)
  9. Gaia Online Question(6)
  10. Question: Vector Based Animation?(4)
  11. 4 Ram Slots Question(6)
  12. Does Science Answer All Our Questions?(13)
  13. Force Object To Load Last(2)
  14. Mysql Question(inserting Number From A Textfield)(3)
  15. File Storage Question?(4)


 



- Lo-Fi Version Time is now: 23rd November 2008 - 04:56 PM