추가 문자열 (예 : "/ testing123"등)이 포함 된 RSS 피드의 모든 URL을 추가하려고합니다. 은 RSS에서 원래 URL 형식은 다음과 같습니다PHP RSS 피드에 모든 URL 추가
<link rel="alternate" type="text/html" href="http://website.com/item/name1/2162561"/>
<link rel="alternate" type="text/html" href="http://website.com/item/name2/2162435"/>
는 등, 내가 for 루프에서 않는 str_replace와 정규 표현식을 사용하지만 난 그것을 제대로 작동하고 내가 preg_replace이다를 사용하는 경우 내가 오류를 얻을 얻을 수없는 것. 난 그냥 문자열의 URL을 반향하는 경우 추가 내가 방법을 표시하지만 난 않는 str_replace를 사용할 때 다음의 URL 대신 다음과 같습니다
http://website.com/testing123/item/name1/2162561
http://website.com/testing123/item/name2/2162435
나는 그들이 얻을 끝에 APPEND 문자열로 URL을 필요 이 같은 그러나 대체 : 내가 가지고
<link rel="alternate" type="text/html" href="http://website.com/item/name1/2162561/testing123"/>
<link rel="alternate" type="text/html" href="http://website.com/item/name2/2162435/testing123"/>
코드는 다음과 같습니다
<?php
// The append string
$append = '/testing123';
// The file
$file = "RSS.txt";
// Get the files contents
$contents = file_get_contents($file);
// The search pattern
$SearchPattern = '/href=["|\'](.[^"|\']+)/i';
// Run preg_match_all to grab all the Matches
preg_match_all($SearchPattern, $contents, $Matches);
// Check to see if we have at least 1 match
$MatchCount = count($Matches[0]);
// If there is more than 1 match then run a for loop
if ($MatchCount > 0) {
for ($i=0; $i < $MatchCount ; $i++) {
$temp = $Matches[0][$i];
echo $temp . $append . '<br />'; // Appears to work
//$contents = str_replace($temp, $temp . $append, $contents); // But str_replace doesn't seem to work
//preg_replace($temp, $temp . $append, $contents); // And using preg_replace gives a error
};
};
echo $contents; // Display the contents
?>
원래 조각은 잘 작동하는 것 같다. – Ifthikhan
아니요, website.com 다음에 추가 문자열을 배치하고 있지만 URL 끝에 가야합니다. – zeddex