Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Manage Website Template

    I'm working on a basic website manager. I've incorporated an open source html editor, but it doesn't know what to do with <!--#include virtual="/path/to/file.html" -->

    So it ignores it and does not show it in the editor.. What I want to do is replace an instance like that with something like {INCLUDE=/path/to/file.html} in the $html variable (which contains the web page html that I'm editing).. so that appears (instead of the blank spot where the other code would be) when I load $html in the HTML editor. then when I submit the modified HTML in the editor, I want to replace {INCLUDE=/path/to/file.html} with the appropriate code <!--#include virtual="/path/to/file.html" --> in $_POST[html] so I can save it to a .html file.

    Can someone help me.. or just point me in the right direction?

    thanks!

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Rather then a virtual include, which not all browsers support, why not a PHP include?

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My PHP application simply opens a .html file and puts the contents into the editor window.. then when the editor window is saved, it writes the contents back to the .html file.. a php include doesn't apply here

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Right... but then what is the virtual include for? The virtual include does the same thing PHP include does... read the contents, display in place... maybe I misunderstood your problem?

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can try again..

    I have a file manager. I want to open an html file and get the contents so I can display it in the editor window of my file manager.. but before I place the code in the editor window, I want replace all virtual include instances with a more friendly code like {INCLUDE=/path/to/file.html}

    so I need to search the $html variable for all virtual includes and replace it with the other code.. then after I save the page, I need to replace all instances of {INCLUDE=/some/file.html} to the vritual include code so I can write it back to the .html file

    I don't need to parse the data that's in the other file, I just need to replace the code that points to it..

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    If its a constant replacement, str_replace will do, if its variable, a regex will do nicely there.

  • #7
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you're not going to actually help with the coding, why bother posting?

    Is something like this what I need?

    PHP Code:
    $html preg_replace("<!--#include virtual=\"[a-zA-Z0-9_/-]\"-->""{INCLUDE=\\0}"$html);

    $html preg_replace("{INCLUDE=[a-zA-Z0-9_/-]}""<!--#include virtual=\"\\0\"-->"$html); 
    Last edited by c0nfus3d1; 11-16-2010 at 08:18 AM.

  • #8
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    If you're going to insult me, why should I help at all? I'm not in a habit of simply writing out code for people, as it often doesn't help them learn.

    Yes, that'll do the job to switching between them, though your regex is wrong

    PHP Code:
    $html preg_replace('/\<!--#include virtual="([a-z0-9_/-]+?)"--\>/i''{INCLUDE=$1}'$html);

    $html preg_replace('/\{INCLUDE=([a-zA-Z0-9_/-]+?)\}/i''<!--#include virtual="$1"-->'$html); 

  • #9
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, at first I thought you were one of those people just making comments to get your post count up..

    I do have a question about your code though, I'm trying what you posted..

    PHP Code:
    $html preg_replace('/\<!--#include virtual="([a-zA-Z0-9_/-]+?)"--\>/i''{INCLUDE=$1}'$html); 
    I get this message:

    Warning: preg_replace() [function.preg-replace]: Unknown modifier '-'
    I've tried removing the - but then I get an error message about the ]

    Is there something I'm missing?

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by c0nfus3d1 View Post
    Is there something I'm missing?
    Yes. Look at the delimiters. You can't just plonk an unescaped delimiter in the middle of the expression without it throwing a fit.

  • #11
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    You can't just plonk an unescaped delimiter in the middle of the expression without it throwing a fit.
    Which delimiter are you referring to? There's several in there..

  • #12
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    There are exactly two delimiters in a valid regular expression. No more, no less. You have three.

    http://uk.php.net/manual/en/regexp.r...delimiters.php

  • #13
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well I stopped the error message from showing up with this line:

    PHP Code:
    $html preg_replace('/\<!--#include virtual="([a-zA-Z0-9_\/-]+?)"--\>/i''{INCLUDE=$1}'$html); 
    but it still doesn't work like it should..

  • #14
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Judging by your description in post one, you're going the wrong way round, so to cater for either scenario:

    Code:
    $html = preg_replace('~\<\!--#include virtual="([^"]+)"--\>~i', '{INCLUDE=$1}', $html);
    $html = preg_replace('~\{INCLUDE=([^\}]+)\}~i', '<!--#include virtual="$1"-->',  $html);
    Last edited by MattF; 11-17-2010 at 03:41 AM.


  •  

    Posting Permissions

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