English 中文(简体)
mb_ereg_replace 获得配对
原标题:mb_ereg_replace get the matches

I just want to know, what are the replacements of the preg_replace function.

能否做到这一点?

For Example:

$string = "test text 12345"; 

$string = mb_ereg_replace( #text|test# ,  $1-test2 ,$string); 

我想知道,“案文”和“测试”是吻合的? 或者说,必须做事吗?

最佳回答

可以通过参考将一个计数变量转换成预选,从而将出现的配对/替代物数目退回。

$string = "test text 12345";
$count = 0;
$string = preg_replace( text ,  test2 , $string, -1, $count);
echo $count; // 1
问题回答

......你可以使用<代码>preg_replace_questback(),这样,你就能够按要求履行习惯职能。 之后,你将能够“看到”匹配,并取代你想要的。

如果这不是你试图发现的一种模式,而仅仅是在扼杀中的案文,那么你可以使用<条码>。

 $findthis = "Apple";
 $container = "Apple Orange Kiwi";

 if (strstr($container,$findthis))
    echo $findthis.  is present ;
 else
    echo  Not found ;
 }

使用preg_match()进行测试,然后使用preg_replace(<>>>/code>,如果你希望与preg_replace_questback(<>产生问题,这也是一种解决办法。

Try this:

$string =  test text 12345 ; 
if ($string != ($replaced = preg_replace( /text/ ,  test2 , $string))) {
    echo  text was replaced ;
}

Though if you don t really need preg_replace, you should use strstr or stristr.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...