FreeSpirit FreeSpirit - 18 days ago 5
PHP Question

PHP Looping content of a page, make and keep changes

Database generated page will be saved as static pages but the url's within the page itself needs to be rewritten. The function is already made.

-> I got an error : implode(): Invalid arguments passed

Goal : the website will be in 3 languages but they all uses the same page index.php. So that's not good enough for google. So static pages will be generated and each language will have his own folder.

While the page is extracted I'll do some url rewrite within the codes of the extracted content. (No not just an Url rewrite for .htaccess. That's not the point at all.)
The pages will change name completely and becomes a static page.

I hope this is clear enough. Hope someone find a way, I tried so much I have almost lost hope to accomplish this.

//At the beginning of the page above the HTML tag.
//Destination for the page and the new name for the page.

$cachefile = "../".trim($_GET['lang'])."/".trim($_GET['page']).".php";

ob_start();

<html>
<body>
...
</body>
</html>

// At the end of the page
$content = ob_get_contents();


// here the loop with my function to find an url

$content = ob_get_contents();

$arrcontent = explode(" ",$content);

$newcontent="";

foreach($arrcontent as $value){

$value = replaceurl_newurlmenu($value, $pathwebsite, $pathmenu);

$newcontent .= array($value);

}

$content = implode(" ",$newcontent);



// then write everything to a page at a new destination

$fp = fopen($cachefile, 'w');
fwrite($fp, $content);
fclose($fp);

ob_end_flush();

Answer

To fix what you have

$arrcontent = explode(" ",$content); 

$newcontent=array();

foreach($arrcontent as $value){

$value = replaceurl_newurlmenu($value, $pathwebsite, $pathmenu);

$newcontent[] = $value;    

}

$content =  implode(" ",$newcontent);

But I would consider looking at array_walk method too.