English 中文(简体)
PHP - How can I rewrite this section to be more Professional?
原标题:PHP - How can I rewrite this section to be more professional?
  • 时间:2011-05-19 20:32:20
  •  标签:
  • php

我如何使这一节更加专业? 将中间6条线合并为1条线有某种办法吗?

if($hyperlink){
  $hyperlink_new=$hyperlink;
  $hyperlink_new=str_replace("row[0]", $row[0], $hyperlink_new);
  $hyperlink_new=str_replace("row[1]", $row[1], $hyperlink_new);
  $hyperlink_new=str_replace("row[2]", $row[2], $hyperlink_new);
  $hyperlink_new=str_replace("row[3]", $row[3], $hyperlink_new);
  $hyperlink_new=str_replace("row[4]", $row[4], $hyperlink_new);
  $hyperlink_new=str_replace("row[5]", $row[5], $hyperlink_new);
  echo "<a href="$hyperlink_new">";
}

谢谢。

最佳回答
if($hyperlink){
    $hyperlink_new=$hyperlink;
    for ($i=0; $i<6; $i+=1) {
        $hyperlink_new=str_replace("row[$i]", $row[$i], $hyperlink_new);
    }
    echo "<a href="$hyperlink_new">";
}
问题回答

添加一环?

if($hyperlink){
  $hyperlink_new=$hyperlink;
  for ($i=0; $i <= 5; $i++) { 
        $hyperlink_new=str_replace("row[$i]", $row[$i], $hyperlink_new);
  }      
  echo "<a href="$hyperlink_new">";
}

假设用我的sql_fetch_row(Vol.I),你可以使用斯特鲁(replace hability)作为参数接收阵列。

if($hyperlink){
  $hyperlink_new = str_replace(
      array("row[0]", "row[1]", "row[2]", "row[3]", "row[4]", "row[5]"), 
      $row,
      $hyperlink
    );
  echo "<a href="$hyperlink_new">";
}

简言之,这里要说明如何使用定期表达和匿名功能反馈。 Probable only Good for php >= 5.3.0

    $link =  row[0] - row[1] - row[2] - row[3] ;
    $rows = array(  zero ,  one ,  two ,  three  );
    $link = preg_replace_callback( "/row[(d+)]/i", function( $matches ) use( $rows ) { return $rows[$matches[1]]; }, $link );
    echo "<a href= $link >";




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

热门标签