Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.



How can I slash out a price to denote a sale price in html and php?

Last updated: 06/30/2009
Add comment
Votes: 0
Comments: 0
Well, the easiest way is to use the <strike> tag in html.  This put a line through your text like so:
Code:

    <strike>$9,999</strike>
Result:
    $9,999

     
For a more complex solution, you can use PHP to create an image, on the fly, putting a red slash across your prices.  Here's a solution:

    <?php
    

    header("Content-type: image/png");
    $string = $_GET['n'];
    $string = "$".number_format($string);
    $im    = imagecreatefrompng("blank.png");
    $black = imagecolorallocate($im, 0, 0, 0);
    $red = imagecolorallocate($im, 196, 0, 0);
    imagestring($im,5, 0, 0, $string, $black);
    $points = array(0,11,1,13,54,6,55,4);
    imagefilledpolygon($im,$points,4,$red);
    imagepng($im);
    imagepng($im,"./".$_GET['n'].".png");
    imagedestroy($im);

    ?>


     
Note a few things:

  • This script gets called like so:  script.php ?n=8888, where n is the price you wish to display.
  • You need a blank (white, or whatever color your background is) image - called blank.png in the same directory as the php script.
  • The data points in the "array" line probably need tweaking, depending how big your image is.  Do some testing, see what works.

Other questions in this category:
What causes an Error 400 when running php on IIS?
Function to handle string substitution in php
What causes array problems with php from one host to another?
My php installation can't write to the Save Session Path - how do I fix it?
how can I output my php arrays in a readable html format using print_r?
How can I get mysql table definitions in my php script?
How can I execute commands on mysql using a php script?
How can I capture the contents of an included file?
php session id keeps changing on every reload - how can I fix this?
How can I get php errors to show in the browser?
How can I keep leading zeros when building a CSV file?
When I try adding text to images in php, the color does not match what I want. How can I fix this?
How can I get bounced emails from my email CGI or PHP script?
How can I modify a script that relies on register globals being turned on?
Configuring htmleditor to do file uploads using php
How can I format my php print_r statements to be more readable in html?
How can I make a state drop down list for my forms?
Why doesn't ftp_connect work in my php script?
How can I force my php scripts to run php5 ?
Why isn't my ioncube installation not working?
How can I remove strange characters from a string in php?
How can I test a portion of my php code without everyone seeing it?
How can I turn off the + / - that shows up in my oscommerce product listing?
How can I authenticate a user in my vbulletin database from a php script?
My php scripts aren't registering $HTTP_GET_VARS variables anymore!
How do I get rid of "Fatal error: Allowed memory size of 8388608 bytes exhausted" in my php scripts?
Resizing images in php doesn't work
I need a php function to put all rows from a mysql query into an array



Powered by KnowledgebasePublisher 1.1
Superb Internet
Content provided by Roberts WebForge, Inc.