Convert HTML code to text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gamenano
Forum Newbie
Posts: 4
Joined: Mon Aug 24, 2009 10:25 am

Convert HTML code to text

Post by gamenano »

Hi everyone, I am new to the forum and this is my first post.

I have an online shop, where one of the mod is to covert orders from html to a PDF file, however, the bit about delivery still show in html code.

Image

I am trying to do something with the template.php file, could anyone tell me what is the code to convert html code to the proper text.

many thanks for help and sugguestion.


Genesis
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Convert HTML code to text

Post by jackpf »

Do you want strip_tags()?
gamenano
Forum Newbie
Posts: 4
Joined: Mon Aug 24, 2009 10:25 am

Re: Convert HTML code to text

Post by gamenano »

Thank you Jackpf,

I am only a beginner with php, so I don't really know what strip_tags() is. I have been doing some reading about strip_tags() on the web, but still not have any idea about this function. So could you educate me a bit more. :banghead:

many thanks in advance Jackpf

Genesis
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Convert HTML code to text

Post by jackpf »

strip_tags()

It basically does what it says on the tin - removes HTML tags.
gamenano
Forum Newbie
Posts: 4
Joined: Mon Aug 24, 2009 10:25 am

Re: Convert HTML code to text

Post by gamenano »

I see. That is what I needed. So how should I to do it? :?:

Genesis
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Convert HTML code to text

Post by jackpf »

Idk, you haven't posted your code. Run strip_tags() on whatever you're writing to the PDF file.
gamenano
Forum Newbie
Posts: 4
Joined: Mon Aug 24, 2009 10:25 am

Re: Convert HTML code to text

Post by gamenano »

You are right mate, the guru whom design this mod have use a function call pdfoc_html_cleanup()

But after a hour of looking where the shipping text was generated, I have no luck. I would guess it would be somewhere around those line.


// line under Totals column
//
$pdf->setLineStyle(1.5);
$tx = $x - PDFOC_PRICING_COLUMN_SIZES + 15;
$pdf->line($tx,$pos,$x+13,$pos); // tweak this value to match end of your table

$pos -= PDFOC_SECTION_DIVIDER;

for ($i = $nexttotal, $n = sizeof($order->totals); $i < $n; $i++) {

// check whether too far down page to print more totals
//
if ($pos < PDFOC_BOTTOM_MARGIN) {
$secondpage = true;
return;
}

$pdf->ezSetY($pos+PDFOC_PRODUCT_TOTALS_LEADING);
$x -= PDFOC_PRICING_COLUMN_SIZES;
$pdf->ezText("<b>" . pdfoc_html_cleanup($order->totals[$i]['title']) . "</b>",PDFOC_TABLE_HEADER_FONT_SIZE,array('justification'=> 'right','aright'=>$x));
$x += PDFOC_PRICING_COLUMN_SIZES;
$pdf->ezSetY($pos+PDFOC_PRODUCT_TOTALS_LEADING);
$pdf->ezText(pdfoc_html_cleanup($order->totals[$i]['text']),PDFOC_TABLE_HEADER_FONT_SIZE,array('justification'=> 'right','aright'=>$x));
// $pdf->addText($x,$pos,PDFOC_PRODUCT_TOTALS_FONT_SIZE,pdfoc_html_cleanup($order->totals[$i]['text']), $order->info['currency_value']);
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Convert HTML code to text

Post by jackpf »

I'm afraid I have no idea what that code does....

Probably best to ask the person who coded it.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Convert HTML code to text

Post by Eran »

This looks like a PDF generation routine and also it looks like some of the tags are a part of the code. You will need to remove those, as well as run strip_tags() on the textual sources (instead of pdfoc_html_cleanup)
Post Reply