feedback, comments on this php-delimiter scrubbing program?

Gary Kline kline at thought.org
Tue Jun 16 01:21:21 UTC 2009


guys,

last night i was lost with a slightly shorter version of this.
even looking at a printout did nothing.  this morning i had another go
and went in a corner and started at the code.  finally i figured it out.
this *seems* to work...  The only thing this does is remove the "<?"
and "?>" delimiters.  i'll go more into my rationale later on.

i'm pretty sure i can tighten up on this; getting it to work was my main
goal.  can any of you break this?

gary

Encl: dephp.c, test


-- 
 Gary Kline  kline at thought.org  http://www.thought.org  Public Service Unix
$Id: dephp.c,v 1.6 2009/06/16 01:05:47 kline Exp kline $

#include <stdio.h>

int 
main()
{
   int ch;
   do
   {
      if ((ch = getchar()) != EOF)
      switch (ch)
      {
      case '>':
	 putchar (ch);
         break;
      case '<':
	 putchar (ch);
	 switch ((ch = getchar()) )
	 {
	 case '?':
	    ch = getchar();
	    while (1)
	    {
	       if (ch == '?' && (ch = getchar()) == '>')
	       {
		  break;
	       } 
	       else
	       {
		  ch = getchar();
	       }
	    }
	    break;
      case '>':
	 putchar (ch);
         break;
	 default:
	    putchar(ch);
	    break;
	 }
	 break;
      default:
         putchar (ch);
      }
   }
   while (ch != EOF);

	return 0;
}
// test

foo
bar
<?
baz
?>

blah, blah 
<
>
<?lll?>
blah, blah:
more HERE.

<>

<  >

<
>

<

>


<?php
?>




More information about the freebsd-questions mailing list