PHP
 Computer >> コンピューター >  >> プログラミング >> PHP

PHP – mb_ereg_replace()関数–正規表現をマルチバイトサポートに置き換えます


PHPでは、 mb_ereg_replace() 正規表現をマルチバイトサポートに置き換えるために使用されます。文字列をスキャンしてパターンに一致するものを探し、一致したテキストを置換に置き換えます。

構文

string mb_ereg_replace(str $pattern, $str $replacement, str $string, str $options)

パラメータ

この関数は、次の4つのパラメーターを受け入れます-

  • $ pattern −このパラメーターは、正規表現パターンに使用されます。パターンでマルチバイト文字を使用する場合があります。

  • $ replace −この置換パラメーターは、指定されたテキストを置換するために使用されます。

  • $ string −このパラメータは、文字列をチェックするために使用されます。

  • $ options −このパラメータは、検索オプションをチェックするために使用されます。

戻り値

mb_ereg_replace() 結果の文字列に対して成功を返すか、エラー時にFalseを返します。文字列が現在のエンコーディングに対して有効でない場合は、NULLを返します。

この例では、UTF-8エンコーディングが使用されています。 mb_ereg_replace() 関数は小さな"h"を置き換えます 大文字の"H" 「HelloWorld」が返されます "hello World"の代わりに 。

<?php
   $result=mb_regex_encoding("UTF-8");
   $string = mb_ereg_replace( "[h]","H","hello World");
   var_dump($result);

   // It returns h as a H
   echo "$string";
?>
として返します

出力

bool(true)
Hello World

  1. PHPでimagefilter()関数を使用して画像にフィルターを適用するにはどうすればよいですか?

    imagefilter() は、特定のフィルターを画像に適用するために使用されるPHPの組み込み関数です。 構文 bool imagefilter(resource $image, int $filtertype, int $arg1, int $arg2, int $arg3, int $arg4) パラメータ imagefilter() 6つの異なるパラメータを取ります-$image、int $ filtertype、int $ arg1、int $ arg2、int $ arg3、int$arg4。 $ image −画像リソースを保持します。 $ filterty

  2. string.replaceの代わりに使用できるPython正規表現は何ですか?

    次のコードは、指定された文字列のすべての文字をに置き換えます。 例 import re line = 'this is a text with<[2> in between</[3> and then there are instances ... where the<[43> number ranges from 0-99</[76>.\ and there are many other lines in the text files \ with<[7> such tags </[8>' line =