FreeSpirit FreeSpirit - 1 year ago 58
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";



// 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);


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);


Answer Source

To fix what you have

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


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download