<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ニワトリの備忘録 &#187; functions.php</title>
	<atom:link href="http://chick.tikidesign.jp/archives/tag/functions-php/feed" rel="self" type="application/rss+xml" />
	<link>http://chick.tikidesign.jp</link>
	<description>3歩あるいたら忘れちゃうんですもの、メモっとかないと！</description>
	<lastBuildDate>Thu, 16 Jul 2020 02:28:43 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>海外テーマの文字化けを回避する</title>
		<link>http://chick.tikidesign.jp/archives/5</link>
		<comments>http://chick.tikidesign.jp/archives/5#comments</comments>
		<pubDate>Mon, 22 Jul 2013 05:36:56 +0000</pubDate>
		<dc:creator><![CDATA[tiki]]></dc:creator>
				<category><![CDATA[カスタマイズ]]></category>
		<category><![CDATA[未分類]]></category>
		<category><![CDATA[functions.php]]></category>
		<category><![CDATA[文字化け]]></category>

		<guid isPermaLink="false">http://chick.tikidesign.jp/?p=5</guid>
		<description><![CDATA[文字を短く区切った部分だけ、文字化けしちゃうのよね〜 マルチバイトのプラグインは有効化してるのに、 文末が◆に？の文字が入る所と入らない所がある。 と思って調べたら下記のサイトを発見！ http://zatzcan.co [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>文字を短く区切った部分だけ、文字化けしちゃうのよね〜<br />
マルチバイトのプラグインは有効化してるのに、<br />
文末が◆に？の文字が入る所と入らない所がある。</p>
<p>と思って調べたら下記のサイトを発見！<br />
<a href="http://zatzcan.com/wordpress/26.html">http://zatzcan.com/wordpress/26.html</a></p>
<p>「function.php」や「tabs.php」などから以下のような記述を見つけ、<br />
2バイト文字に対応したmb_substrに変更とのこと。</p>
<p>■修正前</p>
<pre class="brush: xml; title: ; notranslate">
$text = substr($text,0,$chars_limit);
$text = substr($text,0,strrpos($text,' '));
</pre>
<p>■修正後</p>
<pre class="brush: xml; title: ; notranslate">
$text = mb_substr($text,0,$chars_limit,'UTF-8');
$text = mb_substr($text,0,strrpos($text,' '),'UTF-8');
</pre>
<p>とはいえ、だいぶ書いてあるコードが違ったかも、と思ってメモメモ！</p>
<p>「functions.php」内の記述を修正</p>
<p>■修正前</p>
<pre class="brush: xml; title: ; notranslate">
function print_excerpt($length) {
	global $post;
	$text = $post-&gt;post_excerpt;
	if ( '' == $text ) {
		$text = get_the_content('');
		$text = apply_filters('the_content', $text);
		$text = str_replace(']]&gt;', ']]&gt;', $text);
	}
	$text = strip_shortcodes($text); 
	$text = strip_tags($text);

	$text = substr($text,0,$length);
	$excerpt = reverse_strrchr($text, '.', 1);
	if( $excerpt ) {
		echo apply_filters('the_excerpt',$excerpt);
	} else {
		echo apply_filters('the_excerpt',$text);
	}
}

function reverse_strrchr($haystack, $needle, $trail) {
    return strrpos($haystack, $needle) ? substr($haystack, 0, strrpos($haystack, $needle) + $trail) : false;
}
</pre>
<p>■修正後</p>
<pre class="brush: xml; title: ; notranslate">
function print_excerpt($length) {
	global $post;
	$text = $post-&gt;post_excerpt;
	if ( '' == $text ) {
		$text = get_the_content('');
		$text = apply_filters('the_content',
		$text); $text = str_replace(']]&gt;', ']]&gt;', $text);
	}
	$text = strip_shortcodes($text);
	$text = strip_tags($text);

	$text = mb_substr($text,0,$length,'UTF-8');
	$excerpt = reverse_strrchr($text, '.', 1);
	if( $excerpt ) {
		echo apply_filters('the_excerpt',$excerpt);
	} else {
		echo apply_filters('the_excerpt',$text);
	}
}

function reverse_strrchr($haystack, $needle, $trail) {
	return strrpos($haystack, $needle) ? mb_substr($haystack, 0, strrpos($haystack, $needle) + $trail,'UTF-8') : false;
}
</pre>
<p>ふ〜。長かった。<br />
「substr」を「mb_substr」にして、&#8217;UTF-8&#8217;を追加するのを2箇所づつやっただけですが。<br />
とりあえず、忘れないように・・・</p>
]]></content:encoded>
			<wfw:commentRss>http://chick.tikidesign.jp/archives/5/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
