limit output to only php print/echo statements?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ken

    limit output to only php print/echo statements?

    is there a way to make a php page only output content that is generated
    from php statements, such as print, or echo? ie: if I have whitespace
    (or other text) outside my <?php .... ?block i do not want that to be
    returned.

    of course i can do this by making sure my php file starts with <?php and
    ends with ?and there is no leading or trailing whitespace. but if
    whitespace does creep into my file then it would be neat if there was
    some kind of directive or something that would make sure it doesn't get
    output.

    i ask this because the output from my script will be interpreted by
    another program so i want the output to be specific space delimited
    values with no leading/trailing whitespace.

    of course i should probably just output my content in xml format and
    make my interpreting program parse xml, which accommodates for
    whitespace... but... that would be smart, which i am not.

    thanks!
    ken
  • petersprc

    #2
    Re: limit output to only php print/echo statements?

    Hi,

    Like you said, keeping the file trimmed is the easiest way. You could
    also try using output buffering (ob_start), and trimming the result.

    On Apr 13, 4:31 pm, ken <k...@nospam.co mwrote:
    is there a way to make a php page only output content that is generated
    from php statements, such as print, or echo? ie: if I have whitespace
    (or other text) outside my <?php .... ?block i do not want that to be
    returned.
    >
    of course i can do this by making sure my php file starts with <?php and
    ends with ?and there is no leading or trailing whitespace. but if
    whitespace does creep into my file then it would be neat if there was
    some kind of directive or something that would make sure it doesn't get
    output.
    >
    i ask this because the output from my script will be interpreted by
    another program so i want the output to be specific space delimited
    values with no leading/trailing whitespace.
    >
    of course i should probably just output my content in xml format and
    make my interpreting program parse xml, which accommodates for
    whitespace... but... that would be smart, which i am not.
    >
    thanks!
    ken

    Comment

    • Jerry Stuckle

      #3
      Re: limit output to only php print/echo statements?

      ken wrote:
      is there a way to make a php page only output content that is generated
      from php statements, such as print, or echo? ie: if I have whitespace
      (or other text) outside my <?php .... ?block i do not want that to be
      returned.
      >
      of course i can do this by making sure my php file starts with <?php and
      ends with ?and there is no leading or trailing whitespace. but if
      whitespace does creep into my file then it would be neat if there was
      some kind of directive or something that would make sure it doesn't get
      output.
      >
      i ask this because the output from my script will be interpreted by
      another program so i want the output to be specific space delimited
      values with no leading/trailing whitespace.
      >
      of course i should probably just output my content in xml format and
      make my interpreting program parse xml, which accommodates for
      whitespace... but... that would be smart, which i am not.
      >
      thanks!
      ken
      No. PHP has no control over what's outside the <?php and ?tags.

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • C.

        #4
        Re: limit output to only php print/echo statements?

        On 14 Apr, 03:58, Jerry Stuckle <jstuck...@attg lobal.netwrote:
        ken wrote:
        is there a way to make a php page only output content that is generated
        from php statements, such as print, or echo? ie: if I have whitespace
        (or other text) outside my <?php .... ?block i do not want that to be
        returned.
        >
        of course i can do this by making sure my php file starts with <?php and
        ends with ?and there is no leading or trailing whitespace. but if
        whitespace does creep into my file then it would be neat if there was
        some kind of directive or something that would make sure it doesn't get
        output.
        >
        i ask this because the output from my script will be interpreted by
        another program so i want the output to be specific space delimited
        values with no leading/trailing whitespace.
        >
        of course i should probably just output my content in xml format and
        make my interpreting program parse xml, which accommodates for
        whitespace... but... that would be smart, which i am not.
        >
        thanks!
        ken
        >
        No. PHP has no control over what's outside the <?php and ?tags.
        >
        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstuck...@attgl obal.net
        =============== ===

        Not necessarily true. There's nothing to stop you writing a filter (in
        PHP or other language) which processes a PHP script to return just the
        PHP code, and then pass that through the interpreter - and with
        mod_rewrite it could all be done transparently. But its not the way to
        solve the OPs problem.

        C.

        Comment

        • Jerry Stuckle

          #5
          Re: limit output to only php print/echo statements?

          C. wrote:
          On 14 Apr, 03:58, Jerry Stuckle <jstuck...@attg lobal.netwrote:
          >ken wrote:
          >>is there a way to make a php page only output content that is generated
          >>from php statements, such as print, or echo? ie: if I have whitespace
          >>(or other text) outside my <?php .... ?block i do not want that to be
          >>returned.
          >>of course i can do this by making sure my php file starts with <?php and
          >>ends with ?and there is no leading or trailing whitespace. but if
          >>whitespace does creep into my file then it would be neat if there was
          >>some kind of directive or something that would make sure it doesn't get
          >>output.
          >>i ask this because the output from my script will be interpreted by
          >>another program so i want the output to be specific space delimited
          >>values with no leading/trailing whitespace.
          >>of course i should probably just output my content in xml format and
          >>make my interpreting program parse xml, which accommodates for
          >>whitespace. .. but... that would be smart, which i am not.
          >>thanks!
          >>ken
          >No. PHP has no control over what's outside the <?php and ?tags.
          >>
          >--
          >============== ====
          >Remove the "x" from my email address
          >Jerry Stuckle
          >JDS Computer Training Corp.
          >jstuck...@attg lobal.net
          >============== ====
          >
          >
          Not necessarily true. There's nothing to stop you writing a filter (in
          PHP or other language) which processes a PHP script to return just the
          PHP code, and then pass that through the interpreter - and with
          mod_rewrite it could all be done transparently. But its not the way to
          solve the OPs problem.
          >
          C.
          >
          Exactly true. In your case you're using PHP to filter a file. It does
          not mean that PHP has any control over what's outside the <?php and ?>
          tags. It means you're using a language (it could be ANY language) to
          modify the text.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Mary Pegg

            #6
            Re: limit output to only php print/echo statements?

            ken wrote:
            is there a way to make a php page only output content that is generated
            from php statements, such as print, or echo? ie: if I have whitespace
            (or other text) outside my <?php .... ?block i do not want that to be
            returned.
            >
            of course i can do this by making sure my php file starts with <?php and
            ends with ?and there is no leading or trailing whitespace.
            Make sure there's no leading whitespace (which is pretty obvious) and
            simply leave off the ?at the end.

            --
            "Checking identity papers is a complete waste of time. If anyone can
            be counted on to have valid papers, it will be the terrorists".

            Comment

            • ken

              #7
              Re: limit output to only php print/echo statements?

              Mary Pegg wrote:
              ken wrote:
              >
              >is there a way to make a php page only output content that is generated
              >from php statements, such as print, or echo? ie: if I have whitespace
              >(or other text) outside my <?php .... ?block i do not want that to be
              >returned.
              >>
              >of course i can do this by making sure my php file starts with <?php and
              >ends with ?and there is no leading or trailing whitespace.
              >
              Make sure there's no leading whitespace (which is pretty obvious) and
              simply leave off the ?at the end.
              >
              great suggestion. totally works.
              thanks!
              ken

              Comment

              Working...