doufengsui7449 2012-05-04 04:24
浏览 102

如何从图像名称中删除空格?

In addition to having the image name all lowercase, I'd like to change any spaces to a dash.

<img src="/SC/images/<?php echo strtolower(the_title('','',false)); ?>-header.jpg" border="0" />
  • 写回答

6条回答 默认 最新

  • duanjiu3486 2012-05-04 04:27
    关注

    Simple spaces can be removed using str_replace():

    $image = "foo and bar.png";
    
    // foo-and-bar.png
    echo str_replace( " ", "-", $image );
    

    A more complicated search/replace could be done using a regular expression:

    $image = "foo2   and_ BAR.png";
    
    // foo2-and_-bar.png
    echo preg_replace( "/[^a-z0-9\._]+/", "-", strtolower($image) );
    

    In this example, we permit letters a-z, numbers 0-9, periods and underlines - all other sequences of characters will be replaced with a single dash. The filename is converted to all lower-case prior to being ran through the replacement function.

    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退