Hi,
Im trying to write a regular expression in PHP to check if a submitted
filename has .php on the end of it. For example, filename.html woulod
return false whereas filename.php would return true.
My code is:
if (ereg ("$.php", $filename))
return true;
else
return false;
Obviously my expression is wrong, could someone please tell me what Im
doing wrong. Thanks
Burnsy 5 4420
On Tue, 08 Jan 2008 14:07:31 +0100, bizt <bi******@yahoo.co.ukwrote:
Hi,
Im trying to write a regular expression in PHP to check if a submitted
filename has .php on the end of it. For example, filename.html woulod
return false whereas filename.php would return true.
My code is:
if (ereg ("$.php", $filename))
return true;
else
return false;
Obviously my expression is wrong, could someone please tell me what Im
doing wrong. Thanks
1. Use PCRE not POSIX, the ereg* function will even disappear in PHP6 it
seems.
2. preg_match('/\.php$/',$filename)
--
Rik Wasmus
bizt wrote:
Hi,
Im trying to write a regular expression in PHP to check if a submitted
filename has .php on the end of it. For example, filename.html woulod
return false whereas filename.php would return true.
My code is:
if (ereg ("$.php", $filename))
return true;
else
return false;
Obviously my expression is wrong, could someone please tell me what Im
doing wrong. Thanks
Burnsy
A regex is overkill for a simple string. strcmp() is better in this case.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
..oO(bizt)
>Im trying to write a regular expression in PHP to check if a submitted filename has .php on the end of it. For example, filename.html woulod return false whereas filename.php would return true.
My code is:
if (ereg ("$.php", $filename))
return true; else
return false;
Obviously my expression is wrong, could someone please tell me what Im doing wrong. Thanks
return pathinfo($filename, PATHINFO_EXTENSION) == 'php';
Micha
Michael Fesser wrote:
.oO(bizt)
>Im trying to write a regular expression in PHP to check if a submitted filename has .php on the end of it. For example, filename.html woulod return false whereas filename.php would return true.
My code is:
if (ereg ("$.php", $filename)) return true; else return false;
Obviously my expression is wrong, could someone please tell me what Im doing wrong. Thanks
return pathinfo($filename, PATHINFO_EXTENSION) == 'php';
Micha
Neat.
Michael Fesser wrote:
.oO(bizt)
>Im trying to write a regular expression in PHP to check if a submitted filename has .php on the end of it. For example, filename.html woulod return false whereas filename.php would return true.
My code is:
if (ereg ("$.php", $filename)) return true; else return false;
Obviously my expression is wrong, could someone please tell me what Im doing wrong. Thanks
return pathinfo($filename, PATHINFO_EXTENSION) == 'php';
Micha
Thanks for this. I had never noticed that pathinfo can return a string
rather than an array.
Jeremy This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: YoBro |
last post by:
Hi
I have used some of this code from the PHP manual, but I am bloody hopeless
with regular expressions.
Was hoping somebody could offer a hand.
The output of this will put the name of a form...
|
by: laredotornado |
last post by:
Hi, I'm using PHP 4 and trying to parse through HTML to look for HREF
attributes of anchor tags and SRC attributes of IMG tags. Does anyone
know of any libraries/freeware to help parse through...
|
by: Jocknerd |
last post by:
I'm a Python newbie and I'm having trouble with Regular Expressions when
reading in a text file. Here is a sample layout of the input file:
09/04/2004 Virginia 44 Temple ...
|
by: Holden Caulfield |
last post by:
Hello! Does anyone know a good archive for all different types of
Regular expressions?
I am 90% done a website and the last 10% is putting validation on over
100 fields. They range from...
|
by: bissatch |
last post by:
Hi,
I am trying to use preg_replace to take out all occurances of PHP code
after reading (fread()) the contents of a PHP file. The code I am using
is:
$html = preg_replace("<?php*?>", "",...
|
by: windandwaves |
last post by:
Hi Folk
Some of my clients asked me to create "fancy emails" for them (aka html
formatted emails).
I know how to make a nice html document, but I had trouble creating a simple
way to provide...
|
by: Chris |
last post by:
Hi everyone,
I'm trying to parse through the contents of some text files with regular
expressions, but am new to regular expressions and how to use them in
VB.net.
I'm pretty sure that the...
|
by: peridian |
last post by:
Hi,
I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code.
Most of the techniques I have seen for this involve complex use...
|
by: Henning_Thornblad |
last post by:
What can be the cause of the large difference between re.search and
grep?
This script takes about 5 min to run on my computer:
#!/usr/bin/env python
import re
row=""
for a in range(156000):...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |