LẬP TRÌNH PHP CĂN BẢN - Trang 73

COMPUTER LEARNING CENTER

WWW.HUUKHANG.COM

?>
</body>

</html>


Keát quaû trình baøy nhö hình 7-5.

Hình 7-5: Haøm keát hôïp chuoãi

1.4.

Tìm kieám vaø thay theá chuoãi

Ñeå thay theá chuoãi, baïn söû duïng haøm str_replace, chaúng haïn trong tröôøng hôïp hôïp baïn laáy giaù trò
töø theû nhaäp lieäu, sau ñoù tìm kieám neáu phaùt hieän daáu ‘ thì thay theá thaønh hai daáu nhaùy nhö trang
replace.php.

<html>

<head>
<title>String Functions</title>

</head>

<body>
<h4>That the chuoi</h4>

<?php

$str="";

if

(isset($txtfullname))

$str

=

$txtfullname;

if($str != "");

$str=str_replace("o","a",$str);
echo

$str."<br>";

?>

<form action=replace.php method=post>
fullname: <input name=txtfullname value="<?=$str?>"><br>

<input type=submit value=Submit>

</form>

Giaùo vieân: Phaïm Höõu Khang