mintpeel Posted October 12, 2005 Share Posted October 12, 2005 (edited) Hi, I am wanting to populate my 2co product database when products have been ordered, however my product description contains html tags, so it appears that when the details are posted to 2co the tags cause an error and the rest of the producr_data is voided, or is there some other error in the code below that is preventing the data being sent succesfully? is there a bit of code i can include to strip the html tags before posting the data over to 2co. Is this a matter of adding a command to the payment module php or is it more complicated requiring changes to functions and generals etc. Cheers hold on is the strip_tags($text) shown below used to do this // fill 2Checkout V2 details with osc order info // these fields automate product creation on 2checkout's site. comment out all except c_prod if you do not want this feature for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) { $process_button_string .= tep_draw_hidden_field('c_prod_' . $i, $order->products[$i]['model'] . ',' . $order->products[$i]['qty']); $process_button_string .= tep_draw_hidden_field('c_name_' . $i, $order->products[$i]['name']); // format product description (from Short Description contrib) $product_id = $order->products[$i]['id']; $product_query = tep_db_query("select products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . $product_id . "' and language_id = '" . $languages_id . "'"); $product_description = tep_db_fetch_array($product_query); $text = $product_description['products_description']; $text = strip_tags($text); $text = nl2br($text); $text = str_replace("<br />","<br>",$text); $process_button_string .= tep_draw_hidden_field('c_description_' . $i, $text); $process_button_string .= tep_draw_hidden_field('c_price_' . $i, $order->products[$i]['final_price']); Edited October 12, 2005 by mintpeel Quote Link to comment Share on other sites More sharing options...
kgt Posted October 12, 2005 Share Posted October 12, 2005 The PHP manual has all you need: http://us2.php.net/manual/en/function.htmlspecialchars.php Quote Contributions Discount Coupon Codes Donations Link to comment Share on other sites More sharing options...
mintpeel Posted October 12, 2005 Author Share Posted October 12, 2005 The PHP manual has all you need: http://us2.php.net/manual/en/function.htmlspecialchars.php Cheers, i have no idea what it means, i do not uderstand how to use code, but i will attempt to figure it out :blink: Quote Link to comment Share on other sites More sharing options...
kgt Posted October 12, 2005 Share Posted October 12, 2005 Replace your 'strip_tags' function with the function in the manual. Quote Contributions Discount Coupon Codes Donations Link to comment Share on other sites More sharing options...
mintpeel Posted October 12, 2005 Author Share Posted October 12, 2005 Replace your 'strip_tags' function with the function in the manual. Ok here is what i understnad from reading the manual htmlspecialchars will convert html tags into text such as > < where as the strip_tags function would leave me with just the clean text between the html tags. I didnt include this before, so dont shout cuz it maybe a key bit of inromation my post vars output is thus <form name="checkout_confirmation" action="https://www2.2checkout.com/2co/buyer/purchase" method="post"><input type="hidden" name="c_prod_0" value=",1"><input type="hidden" name="c_name_0" value="Stoat - Future Come And Get Me"><input type="hidden" name="c_description_0" value="<br> About the Cd<br> at the moment the known error is the html tags, i noticed that it had a <br> tag and the function $text = nl2br($text); $text = str_replace("<br />","<br>",$text); adds a <br> tag (i read from the manual) So I am thinking that if i delete these two strings and keep the strip_tags function the product descritpion will be clean text as opposed to the htmlspecialchars which will give me some code such as > in my prod desciption Am I right??? Quote Link to comment Share on other sites More sharing options...
kgt Posted October 12, 2005 Share Posted October 12, 2005 I probably don't understand what you want. Even though there are HTML tags, you want them stripped? So you want to completely drop them? So it looks like strip_tags is not stripping the <br />. Is that what the problem was? Quote Contributions Discount Coupon Codes Donations Link to comment Share on other sites More sharing options...
mintpeel Posted October 12, 2005 Author Share Posted October 12, 2005 I probably don't understand what you want. Even though there are HTML tags, you want them stripped? So you want to completely drop them? So it looks like strip_tags is not stripping the <br />. Is that what the problem was? Sorry for the delay in replying the board is on go slow. No i think that the strip_tags was doing its job but then the code underneath it shown here $text = nl2br($text); $text = str_replace("<br />","<br>",$text); was adding the <br> tags which were casuing the error, since my goal is to post clean text with no html tags. I didnt want to use the charspecialhtml function becuase this would add lots of symbols and text so my product desciprtion would end up looking like this: This?$CD*(lt is really lt$%good (exaagerated a bit) You see? This is very interesting btw, this is my first discussion of php functions where i know what they are doing, its facinating! Really love getting into coding Quote Link to comment Share on other sites More sharing options...
kgt Posted October 12, 2005 Share Posted October 12, 2005 I think I see. The point of nl2br() is to replace \n with <br /> and the point of str_replace is to make the <br />'s into <br>'s. Then strip_tags() can handle stripping the <br>'s. I think you just to perform strip_tags after nl2br() and str_replace(). $text = nl2br($text); $text = str_replace("<br />","<br>",$text); $text = strip_tags( $text ); Quote Contributions Discount Coupon Codes Donations Link to comment Share on other sites More sharing options...
mintpeel Posted October 12, 2005 Author Share Posted October 12, 2005 I think I see. The point of nl2br() is to replace \n with <br /> and the point of str_replace is to make the <br />'s into <br>'s. Then strip_tags() can handle stripping the <br>'s. I think you just to perform strip_tags after nl2br() and str_replace(). $text = nl2br($text); $text = str_replace("<br />","<br>",$text); $text = strip_tags( $text ); Whats is \n? So why do you need other commands will strip_tags not just strip all the html tags? Dont worry if you dont have time to answer i could probably look it up on the net. Thanks for your help!!! :D Quote Link to comment Share on other sites More sharing options...
kgt Posted October 12, 2005 Share Posted October 12, 2005 \n is a unix linebreak. \r\n is a Windows linebreak. When someone uses his or her browser to enter a form and they press the Enter key, the browser will include the linebreaks in the post (depending on what platform the user has). These linebreaks are file linebreaks, but not HTML linebreaks. nl2br() converts file linebreaks to the XHTML-syntactically correct <br />, which is not picked up by strip_tags(). So you need to go in and replace <br /> with <br> before you run strip_tags(). Quote Contributions Discount Coupon Codes Donations Link to comment Share on other sites More sharing options...
mintpeel Posted October 12, 2005 Author Share Posted October 12, 2005 \n is a unix linebreak. \r\n is a Windows linebreak. When someone uses his or her browser to enter a form and they press the Enter key, the browser will include the linebreaks in the post (depending on what platform the user has). These linebreaks are file linebreaks, but not HTML linebreaks. nl2br() converts file linebreaks to the XHTML-syntactically correct <br />, which is not picked up by strip_tags(). So you need to go in and replace <br /> with <br> before you run strip_tags(). Cheers, really getting into php now, thanks for the info! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.