I have a form and insert some chinese words in database and it's ok. Table charset is UTF8. Problem appears when I select this data and send it via mail as HTML attachment.
Then, Chinese doesn't display properly. How to fix charset before send data via mail? Should I use some headers and will it work?
My code looks like that:
//$attachedBodyContent is data from database that contains some chinese words
Mail::send(
"emails.applicationTemplate",
$data,
function($message) use ($data, $template, $subject, $attachedBodyContent) {
$message->to($data['email'], $data['name'])
->from($template['from'],$template['from_name'])
->subject($subject)
->attachData($attachedBodyContent,'YourApplicationData.html');
}
);
When you generate .html attach file you should include in your <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
In this case you can use this code for merge your content with <head>
<?php
$header = '<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>';
$footer = '</body>
</html>';
$allContent = $header.$attachedBodyContent.$footer;
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
This should do it, for further information check the link.
http://www.inventpartners.com/chinese-chars
Related
In PHP, I'm currently making a xpath query but I need to make it case insensitive.
I'm using is XPath 1.0 which from my query means I've got to use some thing called a translate function but I'm unsure of how to do this.
Here is my query test PHP file :
$html = <<<'HTML'
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta NAME="Description" content="Test Case">
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<Link Rel="Canonical" href="http://www.testsite.com/" />
<Title>My Title</Title>
</head>
<Body>
Test Case
</Body>
</html>
HTML;
$domDoc = new DOMDocument();
$domDoc->loadHTML('<?xml encoding="utf-8" ?>' . $html);
// Canonical link
$xpath = new DOMXPath($domDoc);
$canonicalTags = $xpath->query('//link[#rel=\'canonical\']'); // Return nothing
//some use translate(WhatVariable?, 'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ', 'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ')
var_dump($canonicalTags);
Any help would be greatly appreciated. Thanks.
Basically, translate is used to convert dynamic value that you need to compare to be all lower-case (or all upper-case). In this case, you want to apply translate() to rel attribute value, and compare the result to lower-case literal "canonical" (formatted for readability) :
//link[
translate(#rel, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'canonical'
]
I have a html file that want pars tags(Title,A,Name,...) and save them to a excel file .
html tags is persian and when save them into excel file not save corectly.
html file:
<html dir="rtl"><head><meta http-equiv="Content-Language" content="fa">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>ÈÇäß ÕæÊ.ÂãæÒÔ.ÇÏÈíÇÊ.ÚæÇãá Ýí ÇáäÍæ.ÇÓÊÇÏ ãÏÑÓ ÇÝÛÇäí.ÌáÓå 1</title>
<meta name="generator" M.H.SAFARZADE TEHRANI E_BANK_JAME_EMAMALI>
for example i want save title but not save corectly . title tag trust value is :
تدريس استاد مدرس افغاني
but save : ÈÇäß ÕæÊ.ÂãæÒÔ.ÇÏÈíÇÊ.ÚæÇãá Ýí ÇáäÍæ.ÇÓÊÇÏ ãÏÑÓ ÇÝÛÇäí.ÌáÓå 1
in php file i do this :
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
ob_start('mb_output_handler');
header('Content-Type: text/html; charset=utf-8');
and :
$str = mb_convert_encoding($title, "UTF-8");
i can't find answer for my question in web.
please help me ...
thank you
I need help to do this operation. I Have a string like this:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Formatting the report</title><meta http-equiv="refresh" content="5;url=/file/xslt/download/?fileName=somename.pdf"> </head>
I need to extract the fileName parameter. How to do this?
I thing that is possible with regex, but I do not know well this.
Thanks!
Try this..
This will capture the filename
The Pattern is given below
/fileName=(.+?)\"/
<?php
$subject = "<!doctype html> <html> <head> <meta charset="utf-8"> <title>Formatting the report</title><meta http-equiv="refresh" content="5;url=/file/xslt/download/?fileName=somename.pdf"> </head>";
$pattern = '/fileName=(.+)"/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 2);
print_r($matches);
?>
$1->Contains the file name
demo
Try something along the lines of:
$str = '<!doctype html> <html> <head> <meta charset="utf-8"> <title>Formatting the report</title><meta http-equiv="refresh" content="5;url=/file/xslt/download/?fileName=somename.pdf"> </head>';
preg_match('#fileName=(.*)"#', $str, $matches);
print_r($matches);
php simple html dom is clean and good way for trace html and find html elements by selector's like Jquery selectors.
Consider the following PHP code for getting RSS news on a site I'm developing:
<?php
$url = "http://dariknews.bg/rss.php";
$xml = simplexml_load_file($url);
$feed_title = $xml->channel->title;
$feed_description = $xml->channel->description;
$feed_link = $xml->channel->link;
$item = $xml->channel->item;
function getTheData($item){
for ($i = 0; $i < 4; $i++) {
$article_title = $item[$i]->title;
$article_description = $item[$i]->description;
$article_link = $item[$i]->link;
echo "<p><h3>". $article_title. "</h3></p><small>".$article_description."</small><p>";
}
}
?>
The data accumulated by this function should be presented in the following HTML format:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Новини от Дарик</title>
</head>
<body>
<?php getTheData($item);?>
</body>
</html>
As you see I added windows-1251(cyrillic) and utf-8 encoding but the RSS feed is unreadable if I don't change the browser encoding to utf-8. The default encoding in my case is cyrilic but I get unreadable feed. Any help making this RSS readable in cyrilic(it's from Bulgaria) will be greatly appreciated.
I've just tested your code and the Bulgarian characters displayed fine when I removed the charset=windows-1251 meta tag and just left the UTF-8 one. Want to try that and see if it works?
Also, you might want to change your <html> tag to reflect the fact that your page is in Bulgarian like this: <html xmlns="http://www.w3.org/1999/xhtml" lang="bg" xml:lang="bg">
Or maybe you need to force the web server to send the content as UTF-8 by sending a Content-Type header:
<?php
header("Content-Type: text/html; charset=UTF-8");
?>
Just be sure to include this before ANY other content (even whitespace) is sent to the browser. If you don't you'll get the PHP "headers already sent" error.
Maybe you should take a look at htmlentities.
This can convert to html some characters.
$titleEncoded = htmlentities($article_title,ENT_XHTML,cp1251);
I'm trying to change the case of russian characters from upper to lower.
function toLower($string) {
echo strtr($string,'ЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ','ёйцукенгшщзхъфывапролджэячсмитьбю');
};
This is the function I used and the output looks something like this
ЁЙ## ёѹ##`
Can anybody help me with this ?
Thanks in advance
$result = mb_strtolower($orig, 'UTF-8');
(assuming the data is in utf-8)
Specify the charset within the HTML and use mb_strtolower() to convert case:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<head>
<title></title>
</head>
<body>
<?
$string = 'ЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ' ;
echo mb_strtolower($string, 'UTF-8');
?>
</body>
</html>
With the meta-tag it looks like this:
цукенгшщзхъфывапролджэячсмитьбю
Without the meta-tag it looks like this
цукенгшщзхъфывапролджÑÑчÑмитьбю