Results 1 to 6 of 6

Thread: Custom Tags within the files HTML

  1. #1
    Join Date
    Feb 2008
    Posts
    81
    Thanks
    8
    Thanked 5 Times in 5 Posts

    Default Custom Tags within the files HTML

    Hey,

    Actually I am finding a way to parse the a custom html tag that I make within
    the file using an included php.

    Code:
    <?php
    
    include "taglib.php";
    
    ?>
    
    <testtag attribute="">mytext</testtag>
    If this is my PHP file,
    what should I put in the "taglib.php"
    so that is parses the <testtag> element and it's attributes?

    I know using preg_match and other functions,
    can be used to parse a string in common.

    But how should I get the html within the file into the string to parse.

    Hope you can help

    Thanks
    Last edited by midhul; 09-13-2010 at 10:03 AM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You're approaching this backwards: PHP generates HTML, so it must be a string in PHP first, then output as HTML later.

    $mytag = '<testtag attribute="">mytext</testtag>';

    Creating a parser like this isn't that easy.


    Alternatively you could use a function like file() or file_get_contents() to read a ".htm" file and output it. This is the opposite of include: you'd use a page to get the text from a file as a variable and go from there.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Feb 2008
    Posts
    81
    Thanks
    8
    Thanked 5 Times in 5 Posts

    Default

    I'm kinda looking for one which parses script withing the php file.

    Any idea how some of those API's like Facebook and vBulletin do it?
    Like "<fb:login></fb:login>" etc......

    These tags can be put within an included page

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Facebook and vBulletin use a database and bring in the code (text) as a variable. It processes the variable then prints it to the page.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. The Following User Says Thank You to djr33 For This Useful Post:

    midhul (09-13-2010)

  6. #5
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    This may be what your looking for:
    PHP Code:
    <?php
    function customtag($value$text)
    {
    $body="The value in custom tag is $value, the custom text is $text";
    //you can do whatever in here, such as call a database or whatnot.
    return $body;
    }
    function 
    replaceTags($body)
    {
     
    $body preg_replace('!\<customtag=\"(.*?)\"\>(.*?)\<\/customtag\>!Uei'"''.customtag('$1','$2').''"$body);
    //repeat above line for all other tags
    return $body;
    }
    ob_start("replaceTags")
    ?>
    <customtag="customvalue">customtext</customtag>
    <!--***ALL OF YOUR HTML CODE HERE*** -->
    <?
    ob_end_flush
    ();
    ?>
    *Tested, Works, just make sure the page is less that 4MB (the default buffer size, actually it may be 4KB, I'd have to look that up ) or you'll have to use ini_set to increase the buffer
    Last edited by fileserverdirect; 09-11-2010 at 03:35 AM.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  7. The Following User Says Thank You to fileserverdirect For This Useful Post:

    midhul (09-13-2010)

  8. #6
    Join Date
    Feb 2008
    Posts
    81
    Thanks
    8
    Thanked 5 Times in 5 Posts

    Default

    Thanks a lot for all your help guys!

    --->Resolved<------------

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •