相对路径转化成绝对路径_php技巧

提取 Gregarius中的一个函数。可以把网页中的相对路径自动转化成绝对路径。
<? 
function relative_to_absolute($content, $feed_url) { 
    preg_match('/(http|https|ftp):\/\//', $feed_url, $protocol); 
    $server_url = preg_replace("/(http|https|ftp|news):\/\//", "", $feed_url); 
    $server_url = preg_replace("/\/.*/", "", $server_url); 

    if ($server_url == '') { 
        return $content; 
    } 

    if (isset($protocol[0])) { 
        $new_content = preg_replace('/href="\//', 'href="'.$protocol[0].$server_url.'/', $content); 
        $new_content = preg_replace('/src="\//', 'src="'.$protocol[0].$server_url.'/', $new_content); 
    } else { 
        $new_content = $content; 
    } 
    return $new_content; 

?> 

时间: 2024-08-30 08:26:36

相对路径转化成绝对路径_php技巧的相关文章

php相对路径转化成绝对路径

提取 Gregarius中的一个函数.可以把网页中的相对路径自动转化成绝对路径. <?function relative_to_absolute($content, $feed_url) { PReg_match('/(http|https|ftp):\/\//', $feed_url, $protocol); $server_url = preg_replace("/(http|https|ftp|news):\/\//", "", $feed_url);

php 获得当前的脚本网址和相对路径转化成绝对路径正则

<? function relative_to_absolute($content, $feed_url) {  preg_match('/(http|https教程|ftp):///', $feed_url, $protocol);  $server_url = preg_replace("/(http|https|ftp|news):///", "", $feed_url);  $server_url = preg_replace("//.*/&

php把相对路径转换成绝对路径方法

相对路径转化成绝对路径  代码如下 复制代码 function relative_to_absolute($content, $feed_url) {     preg_match('/(http|https教程|ftp):///', $feed_url, $protocol);     $server_url = preg_replace("/(http|https|ftp|news):///", "", $feed_url);     $server_url =

java-Java怎么把 连接access数据库的路径改成相对路径

问题描述 Java怎么把 连接access数据库的路径改成相对路径 import java.awt.event.*; import javax.swing.*; import java.awt.*; import java.awt.Container; import java.util.*; import java.sql.*; class BookBrower implements ActionListener { JFrame f; Container cp; JPanel jpS,jpan

C#中如何把相对路径转成绝对路径?求大神赐教!!

问题描述 C#中如何把相对路径转成绝对路径?求大神赐教!! 解决方案 解决方案二:.././解决方案三:Server.MapPath()解决方案四:Server.MapPath()解决方案五:Server.MapPath()解决方案六:相对根路径,或者用server.mappath解决方案七:注意,在asp.net下的路径最好都是以~开头的路径,既不是"相对路径"也不是"绝对路径".经过asp.net计算出来的"客户端访问路径,可以在你的asp.net部署

把绝对路径改成相对路径

问题描述 我用java调用批处理文件.bat,请问怎么把绝对路径改成相对路径.代码如下:publicvoidrunbat(){Stringcmd="cmd/cstartE:/tr/bin/win32/text.bat";try{Processps=Runtime.getRuntime().exec(cmd);System.out.println(ps.getInputStream());}catch(IOExceptionioe){ioe.printStackTrace();}} 解决

asp相对路径转换成绝对路径

asp相对路径转换成绝对路径 Public Function ChkMapPath(ByVal strPath)  On Error Resume Next  Dim fullPath  strPath = Replace(Replace(Trim(strPath), "//", "/"), "\\", "\")  If strPath = "" Then strPath = "."  

php命令行(cli)模式下报require 加载路径错误的解决方法_php技巧

今天,同事突然告诉我,我写的一个做计划任务的php脚本执行总是不成功. 脚本本身很简单,里面只有包含了几个库文件并执行了一个函数,函数应该没有错误,这个函数在别处也调用过,没有问题.我在本地用浏览器访问页面,执行成功,看来没有问题,我有点怀疑是同事的计划任务的问题.我又打开命令行,用php直接执行脚本,这回报错了,是require 包含文件错误,看来是路径不对. 不明白是什么原因引起的,只是从报错来看是路径不对,我猜测是跟相对路径有关,于是把相对路径的全部改成绝对路径,再执行,问题解决. 在百度

php将金额数字转化为中文大写_php技巧

php将金额数字转化为中文大写 echo toChineseNumber(1234567890);//壹拾贰亿叁仟肆佰伍拾陆万柒仟捌佰玖拾圆 function toChineseNumber($money){ $money = round($money,2); $cnynums = array("零","壹","贰","叁","肆","伍","陆","柒&q