473,795 Members | 3,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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('(=")(pic s/)([0-9a-zA-Z%/ ]+.[a-zA-z]..)(")',$htmlso urce,$imagesint ext);
?>

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 2463
Nel wrote:
<?PHP
$htmlsource = '<img src="pics/hotdog.gif"> text text <img
src="pics/silly%20sausage .gif"> ';
eregi('(=")(pic s/)([0-9a-zA-Z%/ ]+.[a-zA-z]..)(")',$htmlso urce,$imagesint ext);
?>
[...]
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*********@jo hn.dunlop.name> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Nel wrote:
<?PHP
$htmlsource = '<img src="pics/hotdog.gif"> text text <img
src="pics/silly%20sausage .gif"> ';
eregi('(=")(pic s/)([0-9a-zA-Z%/ ]+.[a-zA-z]..)(")',$htmlso urce,$imagesint ext);
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('(=")(pic s/)([0-9a-zA-Z_\-%/ ]+\.[jpgifpnJPGIFPN]{3})(")',$htmls ource,$imagesin text);
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******@nospa m.yahoo.com> wrote in message
news:27******** *************** *******@comcast .com...

"John Dunlop" <us*********@jo hn.dunlop.name> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Nel wrote:
<?PHP
$htmlsource = '<img src="pics/hotdog.gif"> text text <img
src="pics/silly%20sausage .gif"> ';
eregi('(=")(pic s/)([0-9a-zA-Z%/ ]+.[a-zA-z]..)(")',$htmlso urce,$imagesint ext);
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('(=")(pic s/)([0-9a-zA-Z_\-%/ ]+\.[jpgifpnJPGIFPN]{3})(")',$htmls ource,$imagesin text);
can be further shortened:
eregi('(=")(pic s/)([\d\w_\-%/ ]+\.[jpgifpnJPGIFPN]{3})(")',$htmls ource,$imagesin text);

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******@nospa m.yahoo.com> wrote:

"Jim Michaels" <jm******@nospa m.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('(=")(pic s/)([0-9a-zA-Z_\-%/ ]+\.[jpgifpnJPGIFPN]{3})(")',$htmls ource,$imagesin text);


can be further shortened:
eregi('(=")(pic s/)([\d\w_\-%/ ]+\.[jpgifpnJPGIFPN]{3})(")',$htmls ource,$imagesin text);


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

eregi('(=")(pic s/)([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
2383
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 found. $qs and $clean_qs produce the same results. Also, can someone who is fluent with regex stuff take a look at my eregi expressions ? Im not sure if this is the most efficient way of
1
1844
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 $php_login_status = "not ok";
5
6918
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 file name. I can successfully extract the TITLE section, but no luck with the AUTHOR part. Any idea why?
1
3802
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 pattern that merges all the different manners in which a link could be wriiten, Current patterns I can think of include: <a href=x.com> no spaces betwen href, equals and url, no quotation marks around url <a href =x.com> space between href and...
5
2763
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 page for a text match, and return true or false. eregi returns false whatever the case, similar_text returns true whatever the case. Can someone sort me out - oops, HELP me out ?
2
4034
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")); Both resulting in 0 (zero) also tried and without result
25
6510
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 $email = $_POST // Use John Coggeshalls script to validate the email address if(!eregi("^+(\.+)*@+(\.+)*(\.{2,3})$", $email) { echo "The e-mail was not valid";
1
1726
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: alphanumerics, spaces, underscore, hyphen, period, apostrophe if(eregi("^+$", $value)) { return true; }
1
2031
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') ){ die("Access Denied"); }
0
9672
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10436
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9040
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.