What color is the top of the rainbow PHP color text Implementation code

Source: Internet
Author: User
Tags smarty template
Recent popular color words, below is the simple implementation method:
I. Simple implementation of color words

Copy the Code code as follows:


Header ("Content-type:image/png");
$text = $_get[' t '];
$font = ' Stxingka.ttf '; TTF Font
$fontsize = 30;
$size = Imagettfbbox ($fontsize, 0, $font, $text); Get the font length and width range
$DX = ABS ($size [2]-$size [0]) +10;
$dy = ABS ($size [5]-$size [3]);
Building images
$im = Imagecreate ($DX, $dy);
Imagecolorallocate ($im, 255,255, 255); Background color
$fontcolor = Imagecolorallocate ($im, 255, 0, 0); Font Color
Imagettftext ($im, $fontsize, 0, 0, ABS ($size [5]), $fontcolor, $font, $text);
Imagepng ($im);
Imagedestroy ($im);


The above program just expressed some of the basic principles of color, to achieve more complex and beautiful color words, all you have to do is change the font, change the font color, add some background map, and then consider the cache, and so on, the method is similar, friends can try their own.
Two. Color Word application
The above program generated color words through the "? t= text" To pass, but note that these words are best encoded with urlencode, of course, the length should also be limited, this is not the scope of this article discussed.
In addition, the generation of color-coded programs and text-passing programs use UTF-8 encoding, if not, manually turn around.
To use color words, just need to use, wherein, color.php for the generation of color Word program (ie, the above program), XXX for the UrlEncode encoded text (used to generate color words)
Three. Smarty Plug-in
Create a new file modifier.ubb.php under Smarty's plugins directory, as follows:

Copy the Code code as follows:


function Smarty_modifier_ubb ($string) {
$ubb = Array (
'/\[b\ ' (. +?) \[\/b\]/i ', #加粗
'/\[url= (. +?) \](.+?) \[\/url\]/i ', #url
'/\[colorfont\ ' (. +?) \[\/colorfont\]/ie ' #彩字, note that the E modifier is to be added
);
$tohtml = Array (
'\\1',
' \\2 ',
'""'
);
The above is only the implementation of UBB, more UBB tag friends can be implemented by their own methods, of which the color.php root to modify the actual
Return Preg_replace ($ubb, $tohtml, $string);
}


In this way, to display the color Word, simply add in the content
[Colorfont] text [/colorfont]
When displayed, use the UBB modifier in the smarty template, such as {$contentubb}

The above on the rainbow top is what color PHP color text implementation code, including the color of the top of the rainbow content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.