Jump to content


Photo

regular expressions and php


  • Please log in to reply
5 replies to this topic

#1 pdunn

pdunn
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 06 October 2006 - 05:15 PM

Hello,

I want to make a buffer ($buf) that holds my php file. I want to remove the <?php ... ?> section and just hold the html information. I THOUGHT I made a regular expression to do this. I have
$buf = ereg_replace('/[<\?]\w[\?>]/','',$buf);

I also used,

$buf = ereg_replace('/<\?\w\?>/','',$buf);

and it didn't work.

I had notice that even before this section,

$buf = fgets($fd)
$buf = trim($buf);

that $buf only holds a some of the materials, it doesn't hold

<html> blah blah <title>Untitled Document</title>
blah blah
<?php 'partial php_blah'

it holds the rest of php_blah. However,

$buf = strip_tags($buf);
$buf = ereg_replace('/&\w;/', '', $buf);

does holds from "Untitled Document" to the end of the file, even the ending '?>'.

Does anyone knows why and how do I get $buf to hold everything and the proper way to write "erase the information inbetween <? and ?>"?

Thank you,

PDunn

#2 pdunn

pdunn
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 06 October 2006 - 05:31 PM

printing the information in the buffer.

Maybe I'm wrong, maybe what is happening is that the beginning part is not beginning printed out because it is in HTML and HTML tags like

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php

just doesn't get printed.  Well ... how do I print them.  Would this help in being able to eliminate the code inbetween the <?php ?>

Thank you for any help,

P

#3 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 06 October 2006 - 05:33 PM

$regexp = '/^(^<\?(php)?(.*|\s*)/?>)$/';

I think that says, "Starting from the beginning, match what is not <?, followed by an optional php, followed by an character or whitespace, followed by ?>, until the end of the string."
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 06 October 2006 - 05:38 PM

preg_replace('/<\?php.+?\?>/', '', $string);

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#5 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 06 October 2006 - 05:49 PM

effigy, that will miss any embedded <? ... ?>
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#6 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 06 October 2006 - 06:39 PM

If there are embedded tags, I would split on the tag and loop through the result, flagging when you're in a tag.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users