English 中文(简体)
你们如何利用在别克斯的格列克找到一个在左边有一封信的场所,以及一些右边的场所?
原标题:How do you use regex in php to find a space that has a letter on its left and a number on its right?
  • 时间:2011-11-16 04:14:19
  •  标签:
  • php
  • regex

你们如何在位于其左边有一封信的场所和一些右边的场所做一个reg?

在过去的一天里,我做了许多工作,我最多可以找到“字母空间号码”,但我不知道如何找到这封信与编号之间的空间。 我要用 com子取代这一空间。

E.G:

The big red Fox 283 brown balls

将:

The big red Fox,283 brown balls

事先感谢你回答这一问题。 如果你解释答案如何运作,将非常感谢。

最佳回答

http://php.net/manual/en/Function.preg-replace.php rel=“nofollow” a. 履行以下职能:

$string =  The big red Fox 283 brown balls ;
preg_replace( /([a-zA-Z]) ([0-9])/ ,  $1,$2 , $string);

<代码>[a-zA-Z] part of the regexcompes any letter,[0-9]对数。 <代码>/[a-zA-Z][0-9]/共同表示,我们希望与空间之后的任何信件相匹配,然后是一位数字。

圆面括号为,其中允许原封部分为“remembered”(见$1$2),以便我们能够将相应的座标列入替代体。

问题回答

这一工作应当:

$str =  The big red Fox 283 brown balls ;
$regex =  /([a-zA-Z])s(d)/ ;
$str = preg_replace( $regex,  $1,$2 , $str );

你们是否做了这项工作?

<?php
$subject = "The big red Fox 283 brown balls";
$pattern = "/ [0-9]/";
$replacement = ",$0";

echo preg_replace($pattern, $replacement, $subject);
?>

页: 1





相关问题
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 ...

热门标签