文字列を置換する05





☆★データーでの確認★☆

文字列の前後を反転する


strrev関数


  • 文字列内の前後の位置関係を反転させる。
    1バイト単位で反転されるので、全角文字(2バイト文字)は文字化けする。



【 書式 】

PHPスクリプト

<?php
	print strrev("Hello, world!") . "<br>";
	print strrev("Apache & PHP") . "<br>";
	print strrev("ピーエッチピー") . "<br>";
?>


ソースコード


ソースコード【 HTML 】

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="description" content="文字列の処理">
<meta name="keywords" content="PHP,数値の処理">
<meta name="viewport" content="width=device-width"> 
<title>文字列の処理</title>
<!-- IE対策 -->
<!--[if ite IE 9]>
<script src="http://html5shiv.googlecode.com/svn/ttunk/html5.js"></script>
<![endif]-->

<!--[if lte IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->

<style>
  article,aside,dialog,figure,footer,header,
  hgroup,menu,nav,section{ display: block;}
</style>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all">
</head>

<body>

<div id="container">
<header>
	<h1>文字列を置換する</h1>
</header>

	<div class="wrapper">
		<section>
	<h1 class="title_top">文字列の前後を反転する</h1>
<p class="point"><span class="p">P</span>oint</p>

	<h2 class="title_main">strrev関数<span class="title_main_txt">&nbsp;</span></h2>
		<dl>
			<dt>strrev関数</dt>
			<dd>
            	<ul>
					<li>文字列内の前後の位置関係を反転させる。<br>1バイト単位で反転されるので、全角文字(2バイト文字)は文字化けする。</li>
            </dd>
		</dl>

	<h2 class="txt_web">&lt;&nbsp;ブラウザでの表示&nbsp;&gt;</h2>
			<div class="txt_php">
<?php
	print strrev("Hello, world!") . "<br>";
	print strrev("Apache & PHP") . "<br>";
	print strrev("ピーエッチピー") . "<br>";
?>
			</div>
		</section>
<!-- /.wrapper -->
	</div>

<footer>
	<h1>PHPスクリプトの基本</h1>
		<small>Copyright&copy; 2013 webry All Rights Reserved.</small>
		<small>参考資料:<span class="txt_small"><a href="d.hatena.ne.jp/webry/20130825/p2#php_sample_site" target="_blank">速攻&amp;活用! Web開発者のためのPHPベストサンプル集</a></span>
</footer>

<!-- /#container -->
</div>
</body>
</html>

ソースコードCSS

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="description" content="文字列の処理">
<meta name="keywords" content="PHP,数値の処理">
<meta name="viewport" content="width=device-width"> 
<title>文字列の処理</title>
<!-- IE対策 -->
<!--[if ite IE 9]>
<script src="http://html5shiv.googlecode.com/svn/ttunk/html5.js"></script>
<![endif]-->

<!--[if lte IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->

<style>
  article,aside,dialog,figure,footer,header,
  hgroup,menu,nav,section{ display: block;}
</style>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all">
</head>

<body>

<div id="container">
<header>
	<h1>文字列を置換する</h1>
</header>

	<div class="wrapper">
		<section>
	<h1 class="title_top">文字列の前後を反転する</h1>
<p class="point"><span class="p">P</span>oint</p>

	<h2 class="title_main">strrev関数<span class="title_main_txt">&nbsp;</span></h2>
		<dl>
			<dt>strrev関数</dt>
			<dd>
            	<ul>
					<li>文字列内の前後の位置関係を反転させる。<br>1バイト単位で反転されるので、全角文字(2バイト文字)は文字化けする。</li>
            </dd>
		</dl>

	<h2 class="txt_web">&lt;&nbsp;ブラウザでの表示&nbsp;&gt;</h2>
			<div class="txt_php">
<?php
	print strrev("Hello, world!") . "<br>";
	print strrev("Apache & PHP") . "<br>";
	print strrev("ピーエッチピー") . "<br>";
?>
			</div>
		</section>
<!-- /.wrapper -->
	</div>

<footer>
	<h1>PHPスクリプトの基本</h1>
		<small>Copyright&copy; 2013 webry All Rights Reserved.</small>
		<small>参考資料:<span class="txt_small"><a href="d.hatena.ne.jp/webry/20130825/p2#php_sample_site" target="_blank">速攻&amp;活用! Web開発者のためのPHPベストサンプル集</a></span>
</footer>

<!-- /#container -->
</div>
</body>
</html>

ブラウザで表示【 FireFox




IEtester【 IE7




IEtester【 IE8 】




IEtester【 IE9




ブラウザで表示【 Chrome




HTML5 Outliner【 Chrome