繁体   English   中英

将ASP函数转换为PHP

[英]Converting an ASP function to PHP

我正在将录音室网站从基于Windows的服务器移动到Linux服务器。 除了一个使用ASP函数更新新版本的页面之外,它都是html和php。 我一直在尝试使用“echo”来转换它,但我甚至无法接近工作代码。 这里是:

<%

Function PrintRecord(strImage, strAutore, strTitolo, strInfo, strCredits)
    dim strRet
    strRet = strRet + " <td valign=""top"">"
    strRet = strRet + " <div style=""margin-left: 20px""> "
    strRet = strRet + "     <img src=""pictures_works/" + strImage + """ height=""80"" width=""80"" border=""1"">"
    strRet = strRet +"  </td>"
    strRet = strRet + " <td width=""170px"" valign=""top"">"
    strRet = strRet + "     <font class=""TestoPiccoloNo"">"
    strRet = strRet + "         <b>" + strAutore + "</b><br>"
    strRet = strRet + "         " + strTitolo + "<br>"
    strRet = strRet + "         " + strInfo + "<br>"
    strRet = strRet + "<i>- " + strCredits + " </i>"
    strRet = strRet + "     </font>"
    strRet = strRet + " </div> "
    strRet = strRet + " </td>"
    PrintRecord = strRet
End Function

%> 

这是我用来更新的代码:

<%=PrintRecord("somepic.jpg","someband","somerecord","somelabel","whodidwhat")%>

任何帮助,将不胜感激。 谢谢!

  • 用a替换每个+ .
  • $前缀变量
  • 终止行;
  • $strRet = $strRet . 可缩短为$strRet .=
  • 适应开关标签
  • 用大括号括起函数
  • ""替换"" \\"

<?php

function PrintRecord($strImage, $strAutore, $strTitolo, $strInfo, $strCredits) {
    $strRet = '';
    $strRet .= " <td valign=\"top\">";
    $strRet .= " <div style=\"margin-left: 20px\"> ";
    // :
    // ...similar
    // :
    $strRet .= "         <b>" . $strAutore . "</b><br>"; // example for concatenation
    // :
    $strRet .= " </div> ";
    $strRet .= " </td>";
    return $strRet;
}

?>

<?php echo PrintRecord("somepic.jpg","someband","somerecord","somelabel","whodidwhat"); ?>

在PHP中,您可以执行多行字符串。

<?php

function PrintRecord($strImage, $strAutore, $strTitolo, $strInfo, $strCredits){
  $strRet = '
    <td valign="top">
      <div style="margin-left: 20px">
      <img src="pictures_works/'.$strImage.'" height="80" width="80" border="1">
      </div>
    </td>
    <td width="170px" valign="top">
     <div>
       <font class="TestoPiccoloNo">
          <b>'.$strAutore.'</b><br>
          '.$strTitolo.'<br>
          '.$strInfo.'<br>
          <i>- '.$strCredits.'</i>
       </font>
    </div>
   </td>';
  return $strRet;
}
?>

或者通过HEREDOC语法:

<?php
function PrintRecord($strImage, $strAutore, $strTitolo, $strInfo, $strCredits){
    $strRet = << EOT
    <td valign="top">
      <div style="margin-left: 20px">
      <img src="pictures_works/{$strImage}" height="80" width="80" border="1">
      </div>
    </td>
    <td width="170px" valign="top">
     <div>
       <font class="TestoPiccoloNo">
          <b>{$strAutore}</b><br>
          {$strTitolo}<br>
          {$strInfo}<br>
          <i>- {$strCredits}</i>
       </font>
    </div>
   </td>
   EOT;
  return $strRet;
}
?>

并像这样使用它:

<?php echo PrintRecord("somepic.jpg","someband","somerecord","somelabel","whodidwhat");?>

嗯,它看起来怎么样?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM