Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php post中的Wordpress替换字符串_Php_Wordpress_Post_Subset - Fatal编程技术网

Php post中的Wordpress替换字符串

Php post中的Wordpress替换字符串,php,wordpress,post,subset,Php,Wordpress,Post,Subset,嗨,我有另一个页面的rss提要到我的wordpress站点。它可以从rss提要自动创建帖子。但在rss提要中是指向图像的链接,我需要将其更改为另一个链接。 我制作这个脚本 <?php $link="http://www.example.com/thumbs/329/t2_f2ba40a1092b2039a1cf71d2a2b76e91.jpg"; $start = strpos($link, 'thumbs'); $end = strpos($link, 't2_' )+3; $len

嗨,我有另一个页面的rss提要到我的wordpress站点。它可以从rss提要自动创建帖子。但在rss提要中是指向图像的链接,我需要将其更改为另一个链接。 我制作这个脚本

<?php 
$link="http://www.example.com/thumbs/329/t2_f2ba40a1092b2039a1cf71d2a2b76e91.jpg";
$start = strpos($link, 'thumbs');
$end = strpos($link, 't2_'  )+3;
$length = $end - $start;
$vypis = substr($link, $start, $length);
$new = str_replace($vypis, "i/", $link);
echo $new;

?>

是的,那么您应该能够用以下代码替换
ýu内容('Celýčlánek»;')
。它将提取页面内容(不输出到浏览器),使用代码替换URL,然后输出到浏览器。诀窍在于每次识别URL。我需要查看完整的帖子源代码,以便能够使用正则表达式或其他方法来标识要替换的URL

$content = get_the_content(); // get post content
$content = apply_filters('the_content', $content); // apply formatting
$content = str_replace(']]>', ']]&gt;', $content); // apply formatting

// This specifically will need modification, to identify the URL... 
// I would need to see example post content to find out how

$link="http://www.example.com/thumbs/329/t2_f2ba40a1092b2039a1cf71d2a2b76e91.jpg";

$start = strpos($link, 'thumbs');
$end = strpos($link, 't2_'  )+3;
$length = $end - $start;
$vypis = substr($link, $start, $length);
$new = str_replace($vypis, "i/", $link);

$content = str_replace( $link, $new, $content ); // Replace URL in content
echo $content; // Output to browser

我们需要查看更多的代码(如页面/帖子模板的源代码或包含RSS提要呈现的小部件),我编辑我的问题。你需要更多的信息还是足够的信息?谢谢,我对代码做了一些编辑,效果很好!
$content = get_the_content(); // get post content
$content = apply_filters('the_content', $content); // apply formatting
$content = str_replace(']]>', ']]&gt;', $content); // apply formatting

// This specifically will need modification, to identify the URL... 
// I would need to see example post content to find out how

$link="http://www.example.com/thumbs/329/t2_f2ba40a1092b2039a1cf71d2a2b76e91.jpg";

$start = strpos($link, 'thumbs');
$end = strpos($link, 't2_'  )+3;
$length = $end - $start;
$vypis = substr($link, $start, $length);
$new = str_replace($vypis, "i/", $link);

$content = str_replace( $link, $new, $content ); // Replace URL in content
echo $content; // Output to browser