English 中文(简体)
以阵列取代
原标题:Using preg replace with an array
  • 时间:2010-11-03 06:34:44
  •  标签:
  • php

我有一个检查箱清单,它制造了一个阵列,我希望它能够使其价值产生一个图像档案名称以及名称和斜体。

$specs = get( speciesCommon );
$thepath = get_bloginfo( template_directory ); 
foreach($specs as $speci){
echo  <li><img src=" .$thepath. /library/images/icons/species/ .$speci. .gif" width="30" height="30" alt=" .$speci. " title=" .$speci. " /></li>  ;
}

因此,例如,检查箱的数值是悲伤的,因此它会把这一数值印成:

<img src=".../grizzly-bear.gif" title="grizzly-bear" alt="grizzly-bear" .../>

我只想拿没有phen印的题目和斜体。 我进行了审判。

$speci = preg_replace( /-/ , s ,$speci);

但是,我肯定了工作,然后我认识到,图像需要hy子,因此我无法这样做。 关于我如何能够做到这一点的任何想法?

最佳回答

我将使用str_replace作为这一简单替代。 你们还需要使这一结果产生新的变数,因为你们想要利用旧价值和新价值。

foreach($specs as $speci){
  $speci_nohyphen = str_replace( - ,    , $speci);
  echo  <li><img src=" , $thepath,  /library/images/icons/species/ , $speci,  .gif" width="30" height="30" alt=" , $speci_nohyphen,  " title=" , $speci_nohyphen,  " /></li> ;
}
问题回答

暂无回答




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

热门标签