Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

htmlspecialchars 3

Status
Not open for further replies.

Kendel

Programmer
Apr 24, 2002
1,512
US
I'm trying to pass this html to the next page using
htmlspecialchars(html, ENT_QUOTES) but it doesn't work.

html = the stuff below


<p>Carols in the Cave at Farfelu Vineyards<br>
December 4-5 -- 11 am to 5 pm</p>
<p>Kick off the holiday season this weekend at Farfelu’s Carols in the Cave
Holiday Open House. <br>
We’ll have live Christmas carols in our decorated winery, mulled wine and a
roaring outdoor fire. <br>
Start your holiday shopping with unique gift for the winelovers on your list.
Call Farfelu at 540/364-2930 for more information. </p>
<p>Located 60 miles west of Washington, DC at the foot of the Blue Ridge
mountains, Farfelu offers premium, handcrafted wines <br>
in a one-of-a-kind rustic setting. Tour our 1860s dairy barn-turned-tasting room
or linger on our expansive deck, hike our Rappahannock River <br>
trail or challenge your friends to our lawn games (bocce ball, horseshoes,
badminton, volleyball).</p>
<p>Are You Farfelu?</p>
<p>Farfelu (pronounced &quot;far-fuh-loo&quot;) means eccentric or crazy in old French,
which is what everyone thought we were when we planted grapes in the middle of
Virginia’s <br>
apple country in 1967. But we just knew our land could produce wines
of distinction. We were right! </p>
<p>After a three-year revitalization and expansion program, Farfelu is not only
Virginia’s oldest winery, but also one of its finest. Nestled in the foothills of the Blue Ridge
<br>
Mountains, we make handcrafted,
premium wines packed with character and flavor. Through sustainable farming
practices, we grow the highest quality, most intensely <br>
flavored fruit while
protecting the land. We hand harvest, hand sort and gently press our grapes. We
then minimize processing in the cellar to produce fruit-driven wines <br>
that taste
uniquely of their Virginia heritage. </p>
<p>Our Motto: Serious Wine for Un-Serious People!</p>
 
Thanks for the quick response. I'm not PHP programmer. How do I use that addslashes function? just like this:

addslashes(html) ???
 
What is it you are trying to accomplish? Are you trying to output the html characters in the browser literally? If so use the htmlentities() function:

print htmlentities($html);

The addslashes() function is used to escape special characters - typically for database queries.

What exactly are you trying to do?
 
You need to have a string variable in the parantheses (or a string). addslashes($html) or addslashes(&quot;Silly/Willy&quot;);

However, for passing the variable in the URL you should be using the urlencode($var) function - assuming you are using a GET parameter. my.php?html=%20blah%20etcetera

Be aware that there are limits for the amount of information passed in HTML requests. This is browser specific.
 
I'm trying to load a database field into a textbox. Set a cookie equal to this textbox and pass to my site.

$fNotes = htmlentities($db->f(&quot;notes&quot;));

<input type=&quot;hidden&quot; name=&quot;ed&quot; value=&quot;##EV_EVENT_DESC##&quot;>

$ev->replace (&quot;##EV_EVENT_DESC##&quot;, $fNotes);

the $fNote = the html I posted in my very first post.

many thanks.
 
There are 2 different things here I see and can think of:

1. You pass the content of the datafield into the textbox. Since that is HTML to be displayed in an HTMNL page it needs the htmlentitied().

2. When you set your form action to method=&quot;post&quot; and the action=&quot;next.php&quot; (to the next script) the content of the textbox will be available in the $_POST array. No need for a cookie or any encoding. It's all done by the browser and the web server!

Check in your second page:
Code:
print(&quot;<pre>&quot;);
print_r($_POST);
 
To be honest, I am not sure what your code is suppose to do. It looks like you created an object ($ev) and are using a replace function to replace ##EV_EVENT_DESC## with the field. I am not sure how this works.

But, if $fNotes contains the field contents from the database, then the following should work:

<input type=&quot;hidden&quot; name=&quot;ed&quot; value=&quot;<?=htmlentities($fNotes,ENT_QUOTES)?>&quot;>

I used ENT_QUOTES because that is what you used. That should do what you want

 
I changed the form method from get to post & use htmlentities and it finally work. Thanks so much guys.
 
Just so you know (FYI) htmlspecialchars() is basically a strip down version of htmlentities(). It only encodes amp, quot, lt and gt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top