Spaces in file names? - Page 2

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Re: Spaces in file names?

Quoted text here. Click to load it

Should have read the whole thread before sending the last one, PHP
code not much use to you then :-)

Meta Tags, why bother

Re: Spaces in file names?

Quoted text here. Click to load it

Thanks Dave,
will still be useful, as I intend using the same database
on different sites too.
Can you use what you explained just for changing the entries
in URL's and file names though?
The reason being, I use the same data source to create the anchor
text too.


<a href=" ?<%=
"strCompanyName=" & rs1.Fields.Item("strCompanyName").Value

If the entry in strCompanyName has spaces and punctuation
I want it removed or replaced with hyphens from the file name,
but not from the anchor text.
business-listings.asp?strCompanyName=Company-Name">Company Name</a>

with both versions of company name (company-name) pulled from the same

(hope that makes sense)


Re: Spaces in file names?

Quoted text here. Click to load it

Good idea, multiple sites from one database.

Quoted text here. Click to load it


I'm not good enough at PHP to explain it well (still lots to learn) so
this might not be right.

When you pull something from the database you'll give it a specific
name like $filename so I think the easiest way of doing this is create
two unique variables one for filename ($filename) the other for anchor
text ($anchor) and use the replace function only on one of them.

I think a way to do this is take your current variable and use it as a
starting point.

So if your current variable is called $anchor you'd do something like-

$anchor = $filename;
$filename = str_replace(' ','-',$filename);

That would give you a new variable called $filename that uses the same
data as $anchor, but it converts spaces to hyphens (you can remove
other punctuation the same way).

Then you'd use $filename for wherever you used to use $anchor for the

That's the sort of code I tend to use anyway. You can see it in action
here the
filenames are derived from the article titles.

Quoted text here. Click to load it

It makes sense, but not had to do it within ASP yet, I'd assume it's

I think an easier solution is to use the Server.URLEncode function,
something like this (not sure if it's the right format though)-

href=" ?<%=
"strCompanyName=" &

Or maybe-

<a href="<%=
Server.URLEncode(" ?<%=
"strCompanyName=" & rs1.Fields.Item("strCompanyName").Value
%>) %>"><%=(rs1.Fields.Item("strCompanyName").Value)%></a>

I think that replaces the spaces with a +

More Earnings Blog /

Site Timeline