<?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>マルチバイト文字 &#8211; トモデジ  tomodigi.com</title>
	<atom:link href="https://tomodigi.com/tag/%e3%83%9e%e3%83%ab%e3%83%81%e3%83%90%e3%82%a4%e3%83%88%e6%96%87%e5%ad%97/feed/" rel="self" type="application/rss+xml" />
	<link>https://tomodigi.com</link>
	<description>デジタルもアナログも</description>
	<lastBuildDate>Fri, 05 Dec 2014 16:09:21 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>(PHP)mb_strwidthとmb_strimwidth</title>
		<link>https://tomodigi.com/web/phpmb_strwidth%e3%81%a8mb_strimwidth/</link>
					<comments>https://tomodigi.com/web/phpmb_strwidth%e3%81%a8mb_strimwidth/#respond</comments>
		
		<dc:creator><![CDATA[Tomo]]></dc:creator>
		<pubDate>Sat, 06 Dec 2014 19:49:40 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WEB]]></category>
		<category><![CDATA[マルチバイト文字]]></category>
		<guid isPermaLink="false">http://www.tomodigi.com/?p=1982</guid>

					<description><![CDATA[PHPで全角半角混じった文字のバイト数（≒幅）の処理のための関数のメモです。 shift-jisなら全角は2バイトと決め打ちしても良さそうですが、主流のUTF-8では全角は3バイト（一部2バイト）で、見た目とバイト数は一 &#8230; <a href="https://tomodigi.com/web/phpmb_strwidth%e3%81%a8mb_strimwidth/" class="more-link">続きを読む <span class="screen-reader-text">(PHP)mb_strwidthとmb_strimwidth</span> <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>PHPで全角半角混じった文字のバイト数（≒幅）の処理のための関数のメモです。</p>
<p><span class="methodname">shift-jisなら全角は2バイトと決め打ちしても良さそうですが、主流のUTF-8では全角は3バイト（一部2バイト）で、見た目とバイト数は一致しません。</span></p>
<p><span class="refname">mb_strwidth</span>は全角文字（マルチバイト文字）は2、いわゆる半角英数は1で&#8221;文字列の幅&#8221;を返します。また、<span class="methodname">mb_strimwidth</span>は同様に文字列の幅で切り取りを行います。第4引数に「・・・」などとすると、切り取った文字列のあとに「・・・」を足してくれます。（それくらいはPHPでもすぐにできるので、無くてもこまらない機能ですが。）</p>
<p>長さに関係なくレイアウトを維持したい場合などに有用でWeb向きの関数です。<span class="refname">mb_strwidth</span>で文字列の長さを確認して、<span class="methodname">mb_strimwidth</span>で切り取るという感じで使うことが予想されます。ちなみにsubstrのように、後ろから何文字切り抜くというような使い方はできません。そのときはmb_substrを使うべきだと思います。</p>
<p>なお、エンコードの指定は確実に行いましょう。</p>
<p><span class="refname"><span class="methodname">リファレンス「</span><a title="PHP: mb_strwidth - Manual " href="http://php.net/manual/ja/function.mb-strwidth.php" target="_blank">mb_strwidth</a></span>」<br />
<span class="methodname">リファレンス「<a title="PHP: mb_strimwidth - Manual " href="http://php.net/manual/ja/function.mb-strimwidth.php" target="_blank">mb_strimwidth</a></span>」</p>
<p><span class="refname"><span class="methodname"> </span></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://tomodigi.com/web/phpmb_strwidth%e3%81%a8mb_strimwidth/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
