Page 1 of 1

String replace for array not working

Posted: Fri Mar 31, 2006 7:44 pm
by GeXus
Does anyone have an idea as to why this is not working? It is not doing the string replace at all.. Thank You!

Code: Select all

<?

function MakeDirData ($CategoryName, $DirectoryName)
{
//Will be inlucded in index.php
$includes = "<?php include('../../Global.php')?>";

//Replace characters with a blank space
$spacereplace = array("*","?",":",",","'",'"',")","(","#","@","%",".");
str_replace($spacereplace, "", $DirectoryName);
str_replace($spacereplace, "", $CategoryName);


//Replace characters with a dash
$dashreplace = array("/","&","");
str_replace($dashreplace, "-", $DirectoryName);
str_replace($dashreplace, "-", $CategoryName);


//Creates the actual directories
mkdir("$CategoryName/$DirectoryName", 0777);

//Creates index and writes includes
$createIndex = fopen("$CategoryName/$DirectoryName/index.php", "w") or die("can't open file");
fwrite($CreateIndex,$includes);

}

?>

Posted: Fri Mar 31, 2006 7:47 pm
by sofit
You must actually do:

Code: Select all

$var = str_replace(...);
and you are doing only

Code: Select all

str_replace(...);

Posted: Fri Mar 31, 2006 7:53 pm
by RobertGonzalez

Code: Select all

<?
//Replace characters with a blank space
$spacereplace = array("*","?",":",",","'",'"',")","(","#","@","%",".");
$DirectoryName = str_replace($spacereplace, "", $DirectoryName);
$CategoryName = str_replace($spacereplace, "", $CategoryName);

//Replace characters with a dash
$dashreplace = array("/","&","");
$DirectoryName = str_replace($dashreplace, "-", $DirectoryName);
$CategoryName = str_replace($dashreplace, "-", $CategoryName);
?>

Posted: Fri Mar 31, 2006 7:59 pm
by GeXus
excellent, thank you!