FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How to "quote code" in PHP?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
How to "quote code" in PHP? [message #174031] Thu, 19 May 2011 22:31 Go to next message
Mentalguy2k8 is currently offline  Mentalguy2k8
Messages: 3
Registered: May 2011
Karma: 0
Junior Member
I'm trying to put together a little page with a form, so that users can
"translate" any URL into the correct format for posting on a forum.

For instance, they want to share a link and type in "www.google.com"
(without quotes) and the form turns it into "<a href="www.google.com"></a>"
(without the beginning and end quotes) and displays that as text, so that
they can copy/paste it into the forum post box. It will also include an
image-posting version so that it adds the "<img src" etc to an image URL.

How do I "quote" the result so that it displays as plain text rather than a
mess? All I'm getting is a mess of blue code.
Re: How to "quote code" in PHP? [message #174033 is a reply to message #174031] Fri, 20 May 2011 00:47 Go to previous messageGo to next message
Jeff North is currently offline  Jeff North
Messages: 58
Registered: November 2010
Karma: 0
Member
On Thu, 19 May 2011 23:31:47 +0100, in comp.lang.php "Mentalguy2k8"
<Mentalguy2k8(at)gmail(dot)com>
<ir45oo$mik$1(at)dont-email(dot)me> wrote:

> | I'm trying to put together a little page with a form, so that users can
> | "translate" any URL into the correct format for posting on a forum.
> |
> | For instance, they want to share a link and type in "www.google.com"
> | (without quotes) and the form turns it into "<a href="www.google.com"></a>"
> | (without the beginning and end quotes) and displays that as text, so that
> | they can copy/paste it into the forum post box. It will also include an
> | image-posting version so that it adds the "<img src" etc to an image URL.
> |
> | How do I "quote" the result so that it displays as plain text rather than a
> | mess? All I'm getting is a mess of blue code.

A "mess of blue code" could mean that you are not appending the
closing </a>.

To display the text you need to convert < to &lt; and > to &gt; so
your code would look like:
&lt;a href="www.google.com"&gt;&lt;/a&gt;
Have a look at htmlentities
http://au.php.net/manual/en/function.htmlentities.php
Re: How to "quote code" in PHP? [message #174037 is a reply to message #174031] Fri, 20 May 2011 01:47 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/19/2011 6:31 PM, Mentalguy2k8 wrote:
> I'm trying to put together a little page with a form, so that users can
> "translate" any URL into the correct format for posting on a forum.
>
> For instance, they want to share a link and type in "www.google.com"
> (without quotes) and the form turns it into "<a
> href="www.google.com"></a>" (without the beginning and end quotes) and
> displays that as text, so that they can copy/paste it into the forum
> post box. It will also include an image-posting version so that it adds
> the "<img src" etc to an image URL.
>
> How do I "quote" the result so that it displays as plain text rather
> than a mess? All I'm getting is a mess of blue code.

Nothing to do with PHP - this is an HTML.

Look at your HTML source, and if you don't see the problem, try asking
in alt.html. Once you find out what is wrong with your html, change
your PHP code to fix the problem.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: How to "quote code" in PHP? [message #174044 is a reply to message #174031] Fri, 20 May 2011 07:34 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 20/05/2011 0:31, Mentalguy2k8 escribió/wrote:
> I'm trying to put together a little page with a form, so that users can
> "translate" any URL into the correct format for posting on a forum.
>
> For instance, they want to share a link and type in "www.google.com"
> (without quotes) and the form turns it into "<a
> href="www.google.com"></a>" (without the beginning and end quotes) and
> displays that as text, so that they can copy/paste it into the forum
> post box. It will also include an image-posting version so that it adds
> the "<img src" etc to an image URL.
>
> How do I "quote" the result so that it displays as plain text rather
> than a mess? All I'm getting is a mess of blue code.

The function to escape HTML is htmlspecialchars():

http://php.net/htmlspecialchars

Make sure you use it every time you print arbitrary plain text, not only
in this case.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: How to "quote code" in PHP? [message #174046 is a reply to message #174044] Fri, 20 May 2011 08:44 Go to previous messageGo to next message
Mentalguy2k8 is currently offline  Mentalguy2k8
Messages: 3
Registered: May 2011
Karma: 0
Junior Member
""Álvaro G. Vicario"" <alvaro(dot)NOSPAMTHANX(at)demogracia(dot)com(dot)invalid> wrote in
message news:ir55ie$ha3$1(at)dont-email(dot)me...
> El 20/05/2011 0:31, Mentalguy2k8 escribió/wrote:
>> I'm trying to put together a little page with a form, so that users can
>> "translate" any URL into the correct format for posting on a forum.
>>
>> For instance, they want to share a link and type in "www.google.com"
>> (without quotes) and the form turns it into "<a
>> href="www.google.com"></a>" (without the beginning and end quotes) and
>> displays that as text, so that they can copy/paste it into the forum
>> post box. It will also include an image-posting version so that it adds
>> the "<img src" etc to an image URL.
>>
>> How do I "quote" the result so that it displays as plain text rather
>> than a mess? All I'm getting is a mess of blue code.
>
> The function to escape HTML is htmlspecialchars():
>
> http://php.net/htmlspecialchars
>
> Make sure you use it every time you print arbitrary plain text, not only
> in this case.

Thanks guys.

I'm getting in a mess here... I've written the page where the user inputs
the URL into a text box (as "url"), which passes the URL to the results page
as follows:

Cut and paste this link: <?php echo $_POST["url"]; ?>

which will display the text "cut and paste this link" along with the URL
that they entered. I need to add the <a href and the closing </a> around the
URL, without spaces, so that the user can copy the entire line and paste it
into the forum box.
Re: How to "quote code" in PHP? [message #174047 is a reply to message #174046] Fri, 20 May 2011 08:54 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Mentalguy2k8)

> I'm getting in a mess here... I've written the page where the user inputs
> the URL into a text box (as "url"), which passes the URL to the results page
> as follows:
>
> Cut and paste this link: <?php echo $_POST["url"]; ?>
>
> which will display the text "cut and paste this link" along with the URL
> that they entered. I need to add the <a href and the closing </a> around the
> URL, without spaces, so that the user can copy the entire line and paste it
> into the forum box.

<?php echo htmlspecialchars("<a href='{$_POST['url']}'></a>");?>

Something like that.

Micha
Re: How to "quote code" in PHP? [message #174049 is a reply to message #174047] Fri, 20 May 2011 10:21 Go to previous messageGo to next message
Jeff North is currently offline  Jeff North
Messages: 58
Registered: November 2010
Karma: 0
Member
On Fri, 20 May 2011 10:54:07 +0200, in comp.lang.php Michael Fesser
<netizen(at)gmx(dot)de>
<iqact6pduh5u0vduj6i9gttss0on477hr4(at)mfesser(dot)de> wrote:

> | .oO(Mentalguy2k8)
> |
> | >I'm getting in a mess here... I've written the page where the user inputs
> | >the URL into a text box (as "url"), which passes the URL to the results page
> | >as follows:
> | >
> | >Cut and paste this link: <?php echo $_POST["url"]; ?>
> | >
> | >which will display the text "cut and paste this link" along with the URL
> | >that they entered. I need to add the <a href and the closing </a> around the
> | >URL, without spaces, so that the user can copy the entire line and paste it
> | >into the forum box.
> |
> | <?php echo htmlspecialchars("<a href='{$_POST['url']}'></a>");?>
> |
> | Something like that.
> |
> | Micha
So you get some text to show the link you will need:
<?php echo htmlspecialchars("<a
href='{$_POST['url']}'>{$_POST['url']}</a>");?>
Re: How to "quote code" in PHP? [message #174050 is a reply to message #174049] Fri, 20 May 2011 16:21 Go to previous message
Mentalguy2k8 is currently offline  Mentalguy2k8
Messages: 3
Registered: May 2011
Karma: 0
Junior Member
"Jeff North" <jnorthau(at)yahoo(dot)com(dot)au> wrote in message
news:p3gct69n00naeh50sk4f7grl2t87a6g5qg(at)4ax(dot)com...
> On Fri, 20 May 2011 10:54:07 +0200, in comp.lang.php Michael Fesser
> <netizen(at)gmx(dot)de>
> <iqact6pduh5u0vduj6i9gttss0on477hr4(at)mfesser(dot)de> wrote:
>
>> | .oO(Mentalguy2k8)
>> |
>> | >I'm getting in a mess here... I've written the page where the user
>> inputs
>> | >the URL into a text box (as "url"), which passes the URL to the results
>> page
>> | >as follows:
>> | >
>> | >Cut and paste this link: <?php echo $_POST["url"]; ?>
>> | >
>> | >which will display the text "cut and paste this link" along with the
>> URL
>> | >that they entered. I need to add the <a href and the closing </a>
>> around the
>> | >URL, without spaces, so that the user can copy the entire line and
>> paste it
>> | >into the forum box.
>> |
>> | <?php echo htmlspecialchars("<a href='{$_POST['url']}'></a>");?>
>> |
>> | Something like that.
>> |
>> | Micha
> So you get some text to show the link you will need:
> <?php echo htmlspecialchars("<a
> href='{$_POST['url']}'>{$_POST['url']}</a>");?>

Thanks a lot everyone, very useful and I got it working. Very much
appreciated, thanks again.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Regular Expressions
Next Topic: php5-xdebug backported to squeeze from SVN 2.2.0 with trigger functionality
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 14:53:24 GMT 2024

Total time taken to generate the page: 0.02110 seconds