473,378 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

eregi and eregi replace

Nel
Hi all,

I am struggling with understanding a small eregi problem in php4.

My code:
<?PHP
$htmlsource = '<img src="pics/hotdog.gif"> text text <img
src="pics/silly%20sausage.gif"> ';
eregi('(=")(pics/)([0-9a-zA-Z%/ ]+.[a-zA-z]..)(")',$htmlsource,$imagesintext);
?>

var_dump gives this, so I know it's working
Outputs
array(5) {
[0]=>
string(18) "="pics/hotdog.gif""
[1]=>
string(2) "=""
[2]=>
string(5) "pics/"
[3]=>
string(10) "hotdog.gif"
[4]=>
string(1) """
}

What I am trying to do is replace all images in the format ="pics/image.jpg"
with "image.jpg" and at the same time make a list of the files image.jpg.
The problem is how to pick up ALL the occurances, not just the first???

Also how to use replace to remove the pics/ bit of the string.

Thanks,

Nel.
Jan 11 '06 #1
4 2439
Nel wrote:
<?PHP
$htmlsource = '<img src="pics/hotdog.gif"> text text <img
src="pics/silly%20sausage.gif"> ';
eregi('(=")(pics/)([0-9a-zA-Z%/ ]+.[a-zA-z]..)(")',$htmlsource,$imagesintext);
?>
[...]
What I am trying to do is replace all images in the format ="pics/image.jpg"
with "image.jpg" and at the same time make a list of the files image.jpg.
The problem is how to pick up ALL the occurances, not just the first???
preg_match_all(). preg_match is described as an alternative to ereg()
and it stops searching after finding one match, so I assume ereg()
stops then too.

http://www.php.net/manual/en/functio...-match-all.php
Also how to use replace to remove the pics/ bit of the string.


Replace them with the zero string. preg_replace().

http://www.php.net/manual/en/function.preg-replace.php

--
Jock

Jan 11 '06 #2

"John Dunlop" <us*********@john.dunlop.name> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Nel wrote:
<?PHP
$htmlsource = '<img src="pics/hotdog.gif"> text text <img
src="pics/silly%20sausage.gif"> ';
eregi('(=")(pics/)([0-9a-zA-Z%/ ]+.[a-zA-z]..)(")',$htmlsource,$imagesintext);
Be aware that . matches any character: escape it with a \ if you want a
dot.
Also, the range A-z includes [\]^_` along the way. were you trying for this?
eregi('(=")(pics/)([0-9a-zA-Z_\-%/ ]+\.[jpgifpnJPGIFPN]{3})(")',$htmlsource,$imagesintext);
BTW, you should not allow spaces (%20) in filenames on a web site.
?>
[...]
What I am trying to do is replace all images in the format
="pics/image.jpg"
with "image.jpg" and at the same time make a list of the files image.jpg.
The problem is how to pick up ALL the occurances, not just the first???


preg_match_all(). preg_match is described as an alternative to ereg()
and it stops searching after finding one match, so I assume ereg()
stops then too.

Try to tinker with preg_grep?


http://www.php.net/manual/en/functio...-match-all.php
Also how to use replace to remove the pics/ bit of the string.


Replace them with the zero string. preg_replace().

http://www.php.net/manual/en/function.preg-replace.php

--
Jock

Feb 8 '06 #3

"Jim Michaels" <jm******@nospam.yahoo.com> wrote in message
news:27******************************@comcast.com. ..

"John Dunlop" <us*********@john.dunlop.name> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Nel wrote:
<?PHP
$htmlsource = '<img src="pics/hotdog.gif"> text text <img
src="pics/silly%20sausage.gif"> ';
eregi('(=")(pics/)([0-9a-zA-Z%/ ]+.[a-zA-z]..)(")',$htmlsource,$imagesintext);
Be aware that . matches any character: escape it with a \ if you want a
dot.
Also, the range A-z includes [\]^_` along the way. were you trying for
this?
eregi('(=")(pics/)([0-9a-zA-Z_\-%/ ]+\.[jpgifpnJPGIFPN]{3})(")',$htmlsource,$imagesintext);
can be further shortened:
eregi('(=")(pics/)([\d\w_\-%/ ]+\.[jpgifpnJPGIFPN]{3})(")',$htmlsource,$imagesintext);

BTW, you should not allow spaces (%20) in filenames on a web site.
?>


[...]
What I am trying to do is replace all images in the format
="pics/image.jpg"
with "image.jpg" and at the same time make a list of the files
image.jpg.
The problem is how to pick up ALL the occurances, not just the first???


preg_match_all(). preg_match is described as an alternative to ereg()
and it stops searching after finding one match, so I assume ereg()
stops then too.

Try to tinker with preg_grep?


http://www.php.net/manual/en/functio...-match-all.php
Also how to use replace to remove the pics/ bit of the string.


Replace them with the zero string. preg_replace().

http://www.php.net/manual/en/function.preg-replace.php

--
Jock


Feb 14 '06 #4
On 2006-02-14, Jim Michaels <jm******@nospam.yahoo.com> wrote:

"Jim Michaels" <jm******@nospam.yahoo.com> wrote in message
news:27******************************@comcast.com. ..

Be aware that . matches any character: escape it with a \ if you want a
dot.
Also, the range A-z includes [\]^_` along the way. were you trying for
this?
eregi('(=")(pics/)([0-9a-zA-Z_\-%/ ]+\.[jpgifpnJPGIFPN]{3})(")',$htmlsource,$imagesintext);


can be further shortened:
eregi('(=")(pics/)([\d\w_\-%/ ]+\.[jpgifpnJPGIFPN]{3})(")',$htmlsource,$imagesintext);


yeah, both are equally non-functional.
I think what Jim intended was

eregi('(=")(pics/)([0-9A-Z_/\ %-]+\.[fgijnp]{3})(")'
,$htmlsource
,$imagesintext);
But thare's no law that images must have filenames that match that.

This: <img src="randompic.001.php">
is valid if the PHP sets content-type and emits a correctly formed inage...
Bye.
Jasen
Feb 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: fartsniff | last post by:
Hello all. I am starting to work on a URL "cleaner" of sorts. The code below is only checking for a few simple entries on the URL, but for some reason it is not replacing them with "" when...
1
by: Ralph Freshour | last post by:
Can someone please tell me why this function always evaluates to true regardless of what I enter? Thanks... if (!eregi ("A-Za-z", $frm_member_name)) { // invalid characters...
5
by: Jane Doe | last post by:
Hi I took a quick look in the archives, but didn't find an answer to this one. I'd like to display a list of HTML files in a directory, showing the author's name between brackets after the...
1
by: NimP | last post by:
Hi,. I'm trying to detect any links that are contained within an html page using eregi pattern matching. I was wondering if there are any pattern matching geniuses out there who could write a...
5
by: george | last post by:
(driving me nuts) Hi there. I wonder if anyone can help? I'm including a page from Google in search.php, passing some parameters. So far so good. Then I'm asking to look through that Google...
2
by: Frank | last post by:
I'm having trouble detecting whitespaces in strings. Set up this test: echo "<br>example 1:".intval(eregi("^\s","teststring")); echo "<br>example 2:".intval(eregi("^\s","test string")); ...
25
by: Dynamo | last post by:
Hi The following script was taken from John Coggeshall's (PHP consultant) in his article on Zends site at http://www.zend.com/zend/spotlight/ev12apr.php // Get the email address to validate...
1
by: news | last post by:
God, I have read every comment in php.net eregi and Google searched, and I have tried so many different attempts...this is the closest I've gotten to verify a variable contains only:...
1
by: fade2gray | last post by:
Hi, (new to group and a php novice) I'm editing some files using exapmles for reference. (1) // if (!eregi("admin.php", $_SERVER)) { die ("Access Denied"); } (2) if ( !defined('ADMIN_FILE')...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.