#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Cleveland
    Posts
    16
    Rep Power
    0
    Hi

    I have the following HTML snippet:

    $string=<IMG SRC=foo><FONT COLOR=red>foofoofoo</FONT>

    I would like to get the HTML tags and place them into an array called $var so that
    var[1]=<IMG SRC=foo>;
    var[2]=<FONT COLOR=red>;
    var[3]=</FONT>;

    I tried the following code but with no luck:

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

    Any help would be appreciated!!!
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    You should pass the values to the variable in double quotes.


    var[1]=<IMG SRC=foo>;
    var[2]=<FONT COLOR=red>;
    var[3]=</FONT>;


    This was wrong actaully.

    $var[]="<IMG SRC=foo>";
    $var[]="<FONT COLOR=red>";
    $var[]="</FONT>";

    if you want to pass these tags to just a variable then you could use the following..

    $var="<IMG SRC=foo>";
    $var.="<FONT COLOR=red>";
    $var.="</FONT>";




    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Cleveland
    Posts
    16
    Rep Power
    0
    Thanks for your reply but I am afraid that you have misunderstood my question. I have a line of arbitrary HTML code with x tags. I need a way to use regular expressions to store each of those tags into an array. Can this be done with ereg()?

    Thank you!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    I doubt you could do this with a single regular expression. If the page contains JavaScript, for example, there might be many < characters that would throw your regexp off.:

    <script language='javascript'>
    if (x < 10 && y > 20) { ...


    In this case, you would get < 10 && y > as an HTML tag. Similarly, if the content of the page contained any < characters, you'd get thrown.

    You might want to write a loop that checks the file one character at a time. When it hits a <script or <SCRIPT, make it skip ahead until it gets a </script or </SCRIPT (unless of course, you also want to capture any HTML tags embedded in the JavaScript. Then you'll have to come up with similar rules to handle <s that might be in the page content.

Similar Threads

  1. header/footer in html (each page) just like word file
    By nihaarika2002 in forum HTML Programming
    Replies: 4
    Last Post: April 12th, 2004, 01:51 PM
  2. Replies: 0
    Last Post: February 8th, 2004, 11:11 PM
  3. html 2 buttons on a page.
    By hussaim4 in forum HTML Programming
    Replies: 6
    Last Post: January 30th, 2004, 05:09 PM
  4. passing array from page to page...
    By apek in forum PHP Development
    Replies: 3
    Last Post: January 30th, 2004, 03:47 PM
  5. Using an array to fill an HTML table
    By kjzoo in forum HTML Programming
    Replies: 0
    Last Post: January 27th, 2004, 12:17 PM

IMN logo majestic logo threadwatch logo seochat tools logo