Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-16-2010, 12:31 AM   PM User | #1
c0nfus3d1
New to the CF scene

 
Join Date: Nov 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
c0nfus3d1 is an unknown quantity at this point
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!
c0nfus3d1 is offline   Reply With Quote
Old 11-16-2010, 01:10 AM   PM User | #2
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
Rather then a virtual include, which not all browsers support, why not a PHP include?
Keleth is offline   Reply With Quote
Old 11-16-2010, 01:45 AM   PM User | #3
c0nfus3d1
New to the CF scene

 
Join Date: Nov 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
c0nfus3d1 is an unknown quantity at this point
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
c0nfus3d1 is offline   Reply With Quote
Old 11-16-2010, 01:50 AM   PM User | #4
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
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?
Keleth is offline   Reply With Quote
Old 11-16-2010, 02:04 AM   PM User | #5
c0nfus3d1
New to the CF scene

 
Join Date: Nov 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
c0nfus3d1 is an unknown quantity at this point
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..
c0nfus3d1 is offline   Reply With Quote
Old 11-16-2010, 04:26 AM   PM User | #6
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
If its a constant replacement, str_replace will do, if its variable, a regex will do nicely there.
Keleth is offline   Reply With Quote
Old 11-16-2010, 07:41 AM   PM User | #7
c0nfus3d1
New to the CF scene

 
Join Date: Nov 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
c0nfus3d1 is an unknown quantity at this point
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..
c0nfus3d1 is offline   Reply With Quote
Old 11-16-2010, 04:42 PM   PM User | #8
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
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); 
Keleth is offline   Reply With Quote
Old 11-17-2010, 02:10 AM   PM User | #9
c0nfus3d1
New to the CF scene

 
Join Date: Nov 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
c0nfus3d1 is an unknown quantity at this point
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:

Quote:
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?
c0nfus3d1 is offline   Reply With Quote
Old 11-17-2010, 02:26 AM   PM User | #10
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
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.
MattF is offline   Reply With Quote
Old 11-17-2010, 02:46 AM   PM User | #11
c0nfus3d1
New to the CF scene

 
Join Date: Nov 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
c0nfus3d1 is an unknown quantity at this point
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..
c0nfus3d1 is offline   Reply With Quote
Old 11-17-2010, 03:10 AM   PM User | #12
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
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
MattF is offline   Reply With Quote
Old 11-17-2010, 03:25 AM   PM User | #13
c0nfus3d1
New to the CF scene

 
Join Date: Nov 2010
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
c0nfus3d1 is an unknown quantity at this point
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..
c0nfus3d1 is offline   Reply With Quote
Old 11-17-2010, 03:35 AM   PM User | #14
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
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..
MattF is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 08:44 AM.


Advertisement
Log in to turn off these ads.