Problem with quotes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • andy.z@blueyonder.com

    Problem with quotes


    I'm writing a PHP line to the foot of a file using another language. my
    problem is I'm not sure how to write it so that the quotes (both single
    and double) are corret for PHP to process.

    The language I'm writing the PHP line with uses single quotes for a print
    statement.

    Therefore the line I want to write is (reducing to a single array
    element to simplify):

    $myArray = ( "Quote" ="It's time, "he said."" );

    As you can see the quotes are complex already - but this line must be
    written from another language enclosed in single quotes as:

    print '$myArray = ( "Quote" ="It's time, "he said."" );'

    So - my question is - how on earth do I escape such a thing?


    Can anyone help please?


    Andy
  • Rik

    #2
    Re: Problem with quotes

    <andy.z@blueyon der.comwrote:
    >
    I'm writing a PHP line to the foot of a file using another language. my
    problem is I'm not sure how to write it so that the quotes (both single
    and double) are corret for PHP to process.
    >
    The language I'm writing the PHP line with uses single quotes for a print
    statement.
    >
    Therefore the line I want to write is (reducing to a single array
    element to simplify):
    >
    $myArray = ( "Quote" ="It's time, "he said."" );
    >
    As you can see the quotes are complex already - but this line must be
    written from another language enclosed in single quotes as:
    >
    print '$myArray = ( "Quote" ="It's time, "he said."" );'
    >
    So - my question is - how on earth do I escape such a thing?
    >
    >
    Can anyone help please?

    heredoc?
    print '$myArray = ( "Quote" =<<<HEREDOC
    It's time, "he said."
    HEREDOC
    );'
    --
    Rik Wasmus
    Posted on Usenet: any site claiming this as original content or me as an
    contributing member is wrong.
    Ask Smart Questions: http://tinyurl.com/anel

    Comment

    • Rik

      #3
      Re: Problem with quotes

      Rik <luiheidsgoeroe @hotmail.comwro te:
      <andy.z@blueyon der.comwrote:
      >
      >>
      >I'm writing a PHP line to the foot of a file using another language. my
      >problem is I'm not sure how to write it so that the quotes (both single
      >and double) are corret for PHP to process.
      >>
      >The language I'm writing the PHP line with uses single quotes for a
      >print
      >statement.
      >>
      >Therefore the line I want to write is (reducing to a single array
      >element to simplify):
      >>
      >$myArray = ( "Quote" ="It's time, "he said."" );
      >>
      >As you can see the quotes are complex already - but this line must be
      >written from another language enclosed in single quotes as:
      >>
      >print '$myArray = ( "Quote" ="It's time, "he said."" );'
      >>
      >So - my question is - how on earth do I escape such a thing?
      >>
      >>
      >Can anyone help please?
      >
      >
      heredoc?
      print '$myArray = ( "Quote" =<<<HEREDOC
      It's time, "he said."
      HEREDOC
      );'
      Offcourse, the single ' probably has to be escaped for your own language:

      print '$myArray = ( "Quote" =<<<HEREDOC
      It\'s time, "he said."
      HEREDOC
      );'
      --
      Rik Wasmus
      Posted on Usenet: any site claiming this as original content or me as an
      contributing member is wrong.
      Ask Smart Questions: http://tinyurl.com/anel

      Comment

      • Toby A Inkster

        #4
        Re: Problem with quotes

        andy.z wrote:
        $myArray = ( "Quote" ="It's time, "he said."" );
        Backslashes:

        $myArray = array("Quote" ="It's time, \"he said\"");
        As you can see the quotes are complex already - but this line must be
        written from another language enclosed in single quotes as
        What is this other language? What mechanisms does this other language have
        for escaping quotes?

        --
        Toby A Inkster BSc (Hons) ARCS
        Contact Me ~ http://tobyinkster.co.uk/contact
        Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

        * = I'm getting there!

        Comment

        • Jerry Stuckle

          #5
          Re: Problem with quotes

          andy.z@blueyond er.com wrote:
          I'm writing a PHP line to the foot of a file using another language. my
          problem is I'm not sure how to write it so that the quotes (both single
          and double) are corret for PHP to process.
          >
          The language I'm writing the PHP line with uses single quotes for a print
          statement.
          >
          Therefore the line I want to write is (reducing to a single array
          element to simplify):
          >
          $myArray = ( "Quote" ="It's time, "he said."" );
          >
          As you can see the quotes are complex already - but this line must be
          written from another language enclosed in single quotes as:
          >
          print '$myArray = ( "Quote" ="It's time, "he said."" );'
          >
          So - my question is - how on earth do I escape such a thing?
          >
          >
          Can anyone help please?
          >
          >
          Andy
          Or,

          print '$myArray = ( "Quote" ="\"It's time,\" he said." );')

          (I think you want the space after the quote, not before it).

          But if you're trying to display this on an HTML page (i.e. a footer),
          you should think about using the HTML &quot; i.e.

          print '$myArray = ( "Quote" ="&quot;It's time,&quot; he said." );')

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

          Comment

          • Jerry Stuckle

            #6
            Re: Problem with quotes

            andy.z@blueyond er.com wrote:
            I'm writing a PHP line to the foot of a file using another language. my
            problem is I'm not sure how to write it so that the quotes (both single
            and double) are corret for PHP to process.
            >
            The language I'm writing the PHP line with uses single quotes for a print
            statement.
            >
            Therefore the line I want to write is (reducing to a single array
            element to simplify):
            >
            $myArray = ( "Quote" ="It's time, "he said."" );
            >
            As you can see the quotes are complex already - but this line must be
            written from another language enclosed in single quotes as:
            >
            print '$myArray = ( "Quote" ="It's time, "he said."" );'
            >
            So - my question is - how on earth do I escape such a thing?
            >
            >
            Can anyone help please?
            >
            >
            Andy
            And BTW - you'll have to check whatever language you're using to see how
            to handle the single quote within your string.

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

            Comment

            Working...