/    Sign up×
Community /Pin to ProfileBookmark

single quotes while creating a file on a server

I have this little thing that creates a file and names it in accordance with the file title. It forces everything to lowercase, and replaces punctuation marks with hyphens while using the file title for file name.

For example, file with the title

[b]How is this, OK?[/b]

gets to be automatically named
[b]how-is-this–ok-.php[/b]

here is the line that does replacement.

[code=php]$thisFileName = trim(strtolower($_POST[‘file_title’]) );
$thisFileName = str_replace(“.”, “-“, $thisFileName);[/code]

I just used the period sign . to demonstrate, I’ll spare you the other dozen of punctuation marks.

now, considering it’s creating and naming the file, how do I handle quotation marks (both single and double?)

Singles insert the slash right into the file name, and I end up with files named like:
for
[b]File’s Name[/b]
I get
[b]files-name.php[/b]

doubles “break” the code altogether.

Now, my title (File’s Name), is OK; it stores in the database properly, and displayed OK. The actual PHP file it corresponds with gets to keep the slash…

I know a little php, a little enough to be a danger to myself ? so I don’t get some simple things, obviously.

Please, help with this matter.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 14.2005 — I'd probably do this:
[code=php]
$thisFileName = "This, is Nog.Dog\'s test ";
echo "<p>Before: '$thisFileName'</p>n";
$thisFileName = preg_replace('/W/', '-',
stripslashes(strtolower(trim($thisFileName))));
echo "<p>After: '$thisFileName'</p>n";
[/code]

('W' in a regexp means any non-word character: not a letter, number, or underscore.)
Copy linkTweet thisAlerts:
@DariaauthorSep 15.2005 — Thanks!!! That's exactly what I need ?
Copy linkTweet thisAlerts:
@SpectreReturnsSep 16.2005 — Your problem was that magic quotes was off, thus whenever ' is sent, it returns '. Now since you only stripped out ', the is still there.
×

Success!

Help @Daria spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...