String replace for array not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

String replace for array not working

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

}

?>
sofit
Forum Newbie
Posts: 1
Joined: Fri Mar 31, 2006 7:27 pm
Location: Sofia, Bulgaria
Contact:

Post by sofit »

You must actually do:

Code: Select all

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

Code: Select all

str_replace(...);
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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);
?>
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

excellent, thank you!
Post Reply