网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > MetInfo
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 117.95.1.19
Old 2014-12-16, 07:56 AM
Kennydale Kennydale is offline
初级会员
 
Join Date: 2013-11-18
Posts: 2
Kennydale 现在声名狼藉
Default php 字符串截取函数

本文章介绍的是php自带的一个截取字符串的函数,只能处理英文,数字的不能截取中文混排的哦,有需要的朋友可以参考,后面的比较好用,第一个主要是给初学者学学用的。
Code:
<?php
   //构造字符串
  $str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   echo "原字符串:".$str."
 ";
   //按各种方式进行截取
  $str1 = substr($str,5);
   echo "从第5个字符开始取至最后:".$str1."
 ";
   $str2 = substr($str,9,4);
   echo "从第9个字符开始取4个字符:".$str2."
 ";
   $str3 = substr($str,-5);
   echo "取倒数5个字符:".$str3."
 ";
   $str4 = substr($str,-8,4);
   echo "从倒数第8个字符开始向后取4个字符:".$str4."
 ";
   $str5 = substr($str,-8,-2);
   echo "从倒数第8个字符开始取到倒数第2个字符为止:".$str5."
 ";
  ?>
支持中英文混合截取:

Code:
<?php
/*
------------------------------------------------------
参数:
$str_cut    需要截断的字符串
$length     允许字符串显示的最大长度

程序功能:截取全角和半角(汉字和英文)混合的字符串以避免乱码
------------------------------------------------------
*/
function substr_cut($str_cut,$length)
 {
     if (strlen($str_cut) > $length)
     {
         for($i=0; $i < $length; $i++)
         if (ord($str_cut[$i]) > 128)    $i++;
         $str_cut = substr($str_cut,0,$i)."..";
     }
     return $str_cut;
 }
 ?>
Reply With Quote
  #2   IP: 114.238.136.142
Old 2014-12-17, 05:37 AM
La Barge La Barge is offline
初级会员
 
Join Date: 2012-11-18
Posts: 2
La Barge 现在声名狼藉
Default

另一个方法:

Code:
<?php
$path="../upload/201412/1418684851.jpg";
$path=explode('../',$path);   //目前的$path值是一维数据
$path=$path[1];
echo $path;
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 6 (0 members and 6 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
X-Cart Multiple Input Validation Holes Permit SQL Injection and Cross-Site Scripting topvip X-Cart 0 2009-07-21 10:03 AM
用php语言来编写shell脚本 car 代码交流 0 2008-05-05 08:09 PM
Php教程.经验技巧(上) sunshine 代码交流 0 2006-12-15 08:13 PM
Php入门速成 smiling 代码交流 0 2006-12-15 07:30 PM
php.ini中文解释 sunshine 服务器环境搭建 0 2006-02-04 11:05 PM

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 10:56 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.