General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 20th, 2002, 06:14 AM
retr0 retr0 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: UK
Posts: 15 retr0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Need help modifiying a html document

I have a PHP problem I hope that someone may be able to help me.

I need to modifiy a html document string by striping out certain html tags residing [outside of], [html] hightlighted <?php ?> PHP script tags.

i.e.

(<\?) == <?

(\?&lt); == ?>

$str="
<p>I am a html string of text I must be parsed</p><br>
<?php print"I am highlighted html php code and I must not be parsed or effected by the expression"; ?<
I am a another html string of text and I must be parsed
<?php print"I am more html php code"; ?<
etc...
";

I am unsure how to write a Regular Expression or use string macthing to do this. Any ideas?


Gregory

Reply With Quote
  #2  
Old November 20th, 2002, 04:45 PM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
for the regular expression, you just want to find what's between the <?php and ?<, so you can use
PHP Code:
 $string preg_match(/<?php .* ?<); 
to find the chunks one by one, and then do whatever you want with them.. you need slashes before the ? but this php highlighting is gay and removes them

Last edited by crazytrain81 : November 20th, 2002 at 04:47 PM.

Reply With Quote
  #3  
Old November 21st, 2002, 07:14 AM
retr0 retr0 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: UK
Posts: 15 retr0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
crazytrain81

I'm sure that I can do this in PHP. I just don't know how :)

The code below works if <?php and ?> will appear on their own line in a file.

If they are embedded in a line like this then this will not work:
PHP Code:
<a href='<?php echo "$PHP_SELF?op=edit"; ?>'>edit</a

I need to modify the code below to work for those cases as well any idea on how I can do this? The test file should really also be in a string as it is not a remote file...

Or maybe I could use
PHP Code:
 $string preg_match(/<?php .* ?<); 

To skip over the highlighted php html code and then strip all the tags out side of it.

Greg :o)


Here is the test file:

<html>
<head><title>test document</title></head>
<body>
<h2>Title here</h2>
<?php
echo "hello world 1";
?>
<h3>Subtitle here</h3>
<?php
echo "hello world 2";
?>
</body>
</html>

PHP Code:
<?php

// Script demonstrates how to skip over
// php code in a file

$accumulator "";

$file "test_document.html";

$fp = @fopen($file,"r");

if (
$fp) {

  while(
$line fgets($fp,1000)) {

    if (
strstr($line"<?php")) {

      
$accumulator .= $line;
      
$line fgets($fp1000);
      
$php_end_tag_found 0;
      while (
$php_end_tag_found == 0) {
        if (
strstr($line"?>")) {
          
$accumulator .= $line;
          
$php_end_tag_found 1;
        } else {
          
$accumulator .= $line;
          
$line fgets($fp1000);
        }
      }
    } else {
      
$accumulator .= strip_tags($line);
    }

  } 
// end outer while loop

  
fclose($fp);
} else {
  echo 
"error opening document";
}

echo 
$accumulator;

?>

Last edited by retr0 : November 21st, 2002 at 07:40 AM.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Need help modifiying a html document


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT