Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-09-2002, 09:51 PM   #1 (permalink)
rockyracoon
Registered User
 
Join Date: Jun 2002
Posts: 10
rockyracoon is on a distinguished road
Just Signed Up. Eregi Question...

I have an HTML page with blocks of text seperated by two "<hr><hr>" tags.

I am trying to display each "match" as a seperate array item like this:

$matches[6]
$matches[7]
$matches[8]

As of now, only [0] works, and it shows up as one huge block with all the matches! any ideas? preg_match perhaps???

--------------------------------------------
$html = file("test.html");
$string = implode("", $html);

eregi ("<HR><HR>.*<HR><HR>", $string, $matches);

echo "$matches[0]";
---------------------------------------------------
rockyracoon is offline   Reply With Quote
Old 06-09-2002, 09:56 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
hey rocky.. thanks for signing up =)

can i see an example of the HTML page you are trying to parse?

you can attach it if you want. i think it will make more sense to me if i can see that.

thanks,
-mike

ps. feel free to email it to me if you'd rather do that.

Last edited by sde; 06-09-2002 at 10:02 PM.
sde is offline   Reply With Quote
Old 06-09-2002, 10:21 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
http://www.milanointeractive.com/eregi.php

this is what the text.html looks like:
-----------------------------------------------------
<hr><hr>this is some text <hr><hr>
<hr><hr>aaaaaaaaaa <hr><hr>
<hr><hr>bbbbbbbb<hr><hr>
<hr><hr>ccccccc <hr><hr>
<hr><hr>dddddddd <hr><hr>
----------------------------------------------------

and this is what eregi.php looks like:
---------------------------------------------------

<?

$html = file("test.html");
$string = implode("", $html);

eregi ("<HR><HR>.*<HR><HR>", $string, $matches);

foreach($matches as $a){
echo "$a<br>";
}

?>

---------------------------------------------------

not sure if that is what you were trying to do... now you can always strip away the <hr> tags if you would like to in the foreach statement: for example:


foreach($matches as $a){
str_replace("<hr>","",$a);
echo "$a<br>";
}

anyhow.. good luck
sde is offline   Reply With Quote
Old 06-09-2002, 10:59 PM   #4 (permalink)
rockyracoon
Registered User
 
Join Date: Jun 2002
Posts: 10
rockyracoon is on a distinguished road
Almost...

i actually want to turn each instance (instance being the blocks of text inside the <hr><hr>) and be able to call it from an array.


<hr><hr>this text number 1<hr><hr>
<hr><hr>this text number 2<hr><hr>
<hr><hr>this text number 3<hr><hr>
<hr><hr>this text number 4<hr><hr>

$array[3] will produce "this text number 3"

right now $array[3] or [5] or whatever produces nothing.
$array[0] produces all matches...
rockyracoon is offline   Reply With Quote
Old 06-09-2002, 11:15 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
lets look at this a little different:

<?
// this brings each line from test.html into an array "html[]"
$html = file("test.html");

// this brings all elements from the array $html[] into one variable named $string
$string = implode("", $html);

// this takes all places where there are 4 hr tags.. and make them 2
$string=str_replace("<hr><hr><hr><hr>","<hr><hr>", $string);

// now explode $string into an array
$array=explode("<hr><hr>",$string);
?>

hehe, how fun .. i didn't test this, but i think it might work.

Last edited by sde; 06-09-2002 at 11:21 PM.
sde is offline   Reply With Quote
Old 06-12-2002, 07:36 PM   #6 (permalink)
MiLady Mirlyn
lady gamer
 
MiLady Mirlyn's Avatar
 
Join Date: May 2002
Location: Right behind you...
Posts: 92
MiLady Mirlyn is on a distinguished road
Looks like more NUM material to me...

RockyRacoon... wanna make it into one once you get it worked out? :rock:
__________________
Gun control is being able to hit your target!

MiLady Mirlyn is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick question on <table>'s Redline HTML, XML, Javascript, AJAX 3 10-30-2004 08:12 PM
DB Design Question Part II sde Program Design and Methods 3 05-10-2003 12:24 PM
HTML question... dyslexik HTML, XML, Javascript, AJAX 6 03-12-2003 05:07 AM
Nagging question jeffro Lounge 1 03-08-2003 06:46 PM
Question about a php prediction script(Great Site!) Geetazz PHP 15 06-12-2002 05:37 PM


All times are GMT -8. The time now is 07:06 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting