- Php – How to format font style and color in echo
- Best Solution
- Related Solutions
- Change Font Size and Color in PHP
- Change the Font Size and Color Using PHP
- Changing font style in PHP link
- Changing font style in PHP link
- Specific font family inside a form in PHP
- Set Font Color, Font Face and Font Size in PHPExcel
- How to change font (name, size, line spacing) in phpword?
- Как форматировать стиль и цвет шрифта в эхом
Php – How to format font style and color in echo
I have a small snippet of code that I want to style from echo.
foreach($months as $key => $month) < if(strpos($filename,$month)!==false)< echo ' '; > >
This is not working, and I’ve been looking over some resources to try to implement this. Basically I want font-family: Arial and font-size: 11px; and the font-color: #ff0000;
Any php assistance would be helpful.
Best Solution
foreach($months as $key => $month) < if(strpos($filename,$month)!==false)< echo "Movie List for $key 2013"; > >
Related Solutions
Html – How to add some non-standard font to a website
This could be done via CSS:
It is supported for all of the regular browsers if you use TrueType-Fonts (TTF), the Web Open Font Format (WOFF) or Embedded Opentype (EOT).
Css – font-style: italic vs oblique in CSS
In the purest (type designer) sense, an oblique is a roman font that has been skewed a certain number of degrees (8-12 degrees, usually). An italic is created by the type designer with specific characters (notably lowercase a) drawn differently to create a more calligraphic, as well as slanted version.
Some type foundries have arbitrarily created obliques that aren’t necessarily approved by the designers themselves. some fonts were meant not to be italicized or obliqued. but people did anyway. And as you may know, some operating systems will, upon clicking the ‘italic’ icon, skew the font and create an oblique on the fly. Not a pleasant sight.
It’s best to specify an italic only when you’re sure that font has been designed with one.
Related Question
Change Font Size and Color in PHP
PHP doesn’t have built-in functionality for changing the font size or color. We can use HTML and CSS with PHP to change the font size and color.
This tutorial demonstrates how to change font size and color using PHP.
Change the Font Size and Color Using PHP
We can echo an HTML tag with CSS to change the font size and color of the text.
php $string= "Welcome! This page doesn't exist!"; echo $string."
"; //Change the fontsize using PHP, HTML and css through echo echo ' ' . $string. ', New Page'; //Change the font color using PHP, HTML and css through echo echo "
"; echo ' ' . $string. ', New Page'; ?>
The code above prints three strings. One with original size and color, second with 50px font-size, and third with red font color.
Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.
Changing font style in PHP link
This will work for you: To apply font style to complete excel document: Solution 2: PHPExcel is no longer maintained and replace by phpspreadsheet. Or maybe it is possible to some parsing of loaded document, like some foreach for all paragraphs and then change «font settings» for every paragraph of text?
Changing font style in PHP link
Though I have spent some time on this, I have not been able to find the solution though. I am asked to show a «go back» message after clicking that. This message has to be written with the same font the person click on. Here is my code:
"; echo "Go back"; echo ""; > else< echo "Choose a font style
"; echo "verdana
"; echo "arial
"; > ?>
The tag is no longer supported. Use style attribute with font-family property :
if (isset($_GET['fontStyle']))< $font=$_GET['fontStyle']; // unset($_GET); // unset $_GET array is not necessary echo 'Go back'; > else< echo "Choose a font style
"; echo "verdana
"; echo "arial
"; >
HTML font Tag — Usage, Syntax, Examples, CSS Styles. To change the text color, use the CSS color property instead of the color attribute. CSS font-family or font-face properties replace the face attribute, …
Specific font family inside a form in PHP
I am creating an enquiry form in PHP, using a form I created in HTML. Is it possible to use a specfic font inside the PHP code like you can in HTML? for example:
font-family: 'Quicksand', sans-serif;
Below you can see my PHP code I’m referring to:
$email_to = "billy.farroll@hotmail.com"; $name = $_POST["name"]; $email = $_POST["email"]; $tel = $_POST["tel"]; $msg = $_POST["msg"]; $email_from = "billy@slickfin.com"; // This email address has to be the same email on the server if using Fasthots server i.e. SlickFin server - billy@SlickFin.com you can't put the $email variable entered by user because its not authorised to send it. $message = $_POST["message"]; $email_subject = "Enquiry";
For example, this section (below) I want to use the font-family: ‘Quicksand’, sans-serif; for the email I receive when the form has been filled and submitted. THIS IS MY QUESTION.
$headers = "From: $email .\n"; "Reply-To: $email .\n"; // $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $message = ''; $message .= "Enquiry"; $message .= " Name: " . $name . ""; $message .= "
Email Address: " . $email . "
"; $message .= " Telephone Number: " . $tel . "
"; $message .= " Message: " . $msg ."
"; $message .= "";
Also, here’s my HTML form code:
Done Done Done Done
If you’d like to see the entire index.html and the entire equiry.php files, you can via Github at: https://github.com/billyfarroll/enquiry_slick_one
PHP is not an output format. PHP might manipulate the output, but it is not the output itself. Think about PHP as a calculator and HTML as the numbers on the calculator screen. Your question doesn’t really make sense.
There are many different output formats. HTML is just one of them and is probably what you’ll be working with mostly other than JSON.
It seems in this case you’re sending an HTML email. Most email clients will display HTML and CSS; similar to a web browser. What you’re going to want to do is use PHP to generate some CSS (an output format) and HTML (Also an output format) to get the result you want.
The CSS in your HTML emails is more limited than what you can do in a browser. To ensure compatibility in this particular case , I recommend using inline styles in order to get your desired effect.
To add a font to your HTML email that you’re not expecting the client to have, you could also do something like this.
Note that this will work with some email clients, and not with others. so make sure to use some fallback fonts in your CSS.
Listing available fonts in PHP, I’d like to query what fonts are available on a *nix-like system, ideally using PHP 5.2 or 5.3, but there doesn’t seem to be many libraries available to do …
Set Font Color, Font Face and Font Size in PHPExcel
I’m working in phpexcel . I’m beginner.When I’m using following code and its working fine.
$phpExcel = new PHPExcel(); $phpExcel->getActiveSheet()->getStyle("A1")->getFont()->setBold(true) ->setName('Verdana') ->setSize(10) ->getColor()->setRGB('6F6F6F');
But when I’m using following code and not getting expected result as above.
$phpFont = new PHPExcel_Style_Font(); $phpFont->setBold(true); $phpFont->setName('Verdana'); $phpFont->setSize(15); $phpColor = new PHPExcel_Style_Color(); $phpColor->setRGB('FF0000'); $phpExcel->getActiveSheet()->getStyle('A1')->setFont( $phpFont ); $phpExcel->getActiveSheet()->getStyle('A1')->getFont()->setColor( $phpColor );
Please help me what am I doing wrong in above code.
I recommend you start reading the documentation (4.6.18. Formatting cells). When applying a lot of formatting it’s better to use applyFromArray() According to the documentation this method is also suppose to be faster when you’re setting many style properties. There’s an annex where you can find all the possible keys for this function.
$phpExcel = new PHPExcel(); $styleArray = array( 'font' => array( 'bold' => true, 'color' => array('rgb' => 'FF0000'), 'size' => 15, 'name' => 'Verdana' )); $phpExcel->getActiveSheet()->getCell('A1')->setValue('Some text'); $phpExcel->getActiveSheet()->getStyle('A1')->applyFromArray($styleArray);
To apply font style to complete excel document:
$styleArray = array( 'font' => array( 'bold' => true, 'color' => array('rgb' => 'FF0000'), 'size' => 15, 'name' => 'Verdana' )); $phpExcel->getDefaultStyle() ->applyFromArray($styleArray);
PHPExcel is no longer maintained and replace by phpspreadsheet.
First read the documentation and use applyFromArray() for applying style and read the documentation of phpspreadsheet:
$spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $styleArray = [ 'font' => [ 'bold' => true, 'size' => 14, 'name' => 'Arial' ], 'alignment' => [ 'horizontal' => Alignment::HORIZONTAL_CENTER, 'vertical' => Alignment::VERTICAL_CENTER ], 'borders' => [ 'allBorders' => [ 'borderStyle' => Border::BORDER_THIN, 'color' => ['rgb' => '000000'] ] ] ]; $sheet->getStyle('A1')->applyFromArray($styleArray);
The documentation can be found Here
in other way , you can use :
$objPHPExcel->getActiveSheet() ->getStyle('A1') ->getFont() ->getColor() ->setRGB ('EEEEEE') ;
Html — Changing font style in PHP link, Changing font style in PHP link. Ask Question Asked 4 years, 3 months ago. Modified 4 years, 3 months ago. Viewed 5k times -1 Though I have …
How to change font (name, size, line spacing) in phpword?
Could you please tell me is it possible to — load docx document into phpword , then change font name, size, line spacing in that loaded document and then save it to another docx file?
I’m reading phpword official docx right now, but as I see it’s much more creating a new document (with some font name, size and line spacing trough setting of a paragraph for example) than for changes in loaded document. Or maybe I’m wrong?
So is it possible to change these «font settings» for loaded document? Or maybe it is possible to some parsing of loaded document, like some foreach for all paragraphs and then change «font settings» for every paragraph of text?
Thank you in advance for your help!
Yep, changing some of the document default settings is possible. For example changing the default font definitions:
$phpWord = \PhpOffice\PhpWord\IOFactory::load('myfile.docx'); $phpWord->setDefaultFontSize(50); $phpWord->setDefaultFontName('courier');
for line spacing you can check whether the default value can be modified with the setDefaultParagraphStyles method.
How to use css style in php, Im using php to display data from mysql. Here are my css statements:
Как форматировать стиль и цвет шрифта в эхом
У меня есть небольшой фрагмент кода, который я хочу создать из эха.
Это не работает, и я искал некоторые ресурсы, чтобы попытаться реализовать это. В принципе, я хочу font-family: Arial и font-size: 11px; и цвет шрифта: # ff0000;
Любая помощь php была бы полезна.
foreach($months as $key => $month) < if(strpos($filename,$month)!==false)< echo "Movie List for $key 2013"; > >
echo " Movie List for 2013 ";
Переменные расширяются только в двойных кавычках, а не в одинарных кавычках. Поскольку приведенное выше использование двойных кавычек для строки PHP, я переключился на одинарные кавычки для встроенного HTML, чтобы избежать необходимости избегать кавычек.
Другая проблема с вашим кодом заключается в том, что теги предназначены для ввода блоков CSS, а не для стилизации отдельных элементов. Чтобы стилизовать элемент, вам нужен тег элемента с атрибутом style ; – самый простой элемент – он не имеет никакого собственного форматирования, он просто служит местом для прикрепления атрибутов.
Другой популярный способ написать это с помощью конкатенации строк:
echo ' Movie List for ' . $key . ' 2013 ';
Вы пытаетесь воспроизвести стиль или встроенный стиль? Встраиваемый стиль будет похож на
echo ' < span style = "font-color: #ff0000">Movie List for 2013 ';
Вы также должны использовать стиль «цвет», а не «шрифт-цвет»,
$month) < if(strpos($filename,$month)!==false)< echo " "; > > ?>
В целом, комментарии к двойным и одинарным кавычкам верны в других предложениях. $ Переменные выполняются только в двойных кавычках.