Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Convert all html files to php files

Community Beginner ,
Jun 24, 2009 Jun 24, 2009

Hi there,

I have hundreds of pages .html in my local folder and I want to convert them to .php.

Is there any way to do this in a single shot instead of going to replace every ".html" with ".php"

Help please.

Thanks!

boloco

TOPICS
Server side applications
12.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 26, 2009 Jun 26, 2009

Certainly, you can run html files on a dynamic site. There are two possible scenarios:

  • The server is configured to treat .html files as .php files.
  • The .html files don't contain any PHP code.

In the first scenario, the server automatically passes all files to the PHP engine. If you're on shared hosting, your hosting company is unlikely to agree to this, but you can certainly ask.

In the second scenario, you can convert your files to .php as and when you add PHP code to a file. The problem with this

...
Translate
Advisor ,
Jun 24, 2009 Jun 24, 2009

mac or pc?

If Mac use Automator.app just drag the Get Specified Finder Items action into your workflow then click the add button and add the files you want to rename into the list. After that add a Rename Finder Items action and select replace text from the dropdown option list and for find enter .html and for replace enter .php

Run the workflow and you'll have all the selected file extensions that previously had .html extension now renamed to .php

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 24, 2009 Jun 24, 2009

I have a mac.

Thanks for your answer. I'll try it tomorrow. 2 am now. I better do this when I'm freshly awake.

I'll let you know.

Thanks again,

boloco

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 24, 2009 Jun 24, 2009

www.DwFAQ.info wrote:

Run the workflow and you'll have all the selected file extensions that previously had .html extension now renamed to .php

I haven't tried that, but renaming the files outside Dreamweaver will result in all internal page links breaking. Unfortunately, Dreamweaver doesn't have a feature that batch processes file renaming.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 24, 2009 Jun 24, 2009

I like the answer using automate but David's answer, who's books I study religiously, makes sense.

OK then, I'll take my time and convert the files one by one.

So, David, should I just go ahead and name all my files .php in the future just in case I need to make them dynamic?

Is that ok to run a static site with a .php extension?

Thanks!

Michel

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 24, 2009 Jun 24, 2009

Just like with Automator relinking pages in DW is as easy as using find/replace. Open DW, go to find/replace, find .html and replace with .php and there ya go. That's what find/replace is used for isn't it - finding and replacing things

It is ok to run a static page with .php extension.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 24, 2009 Jun 24, 2009

I thought about that but there is no way to use Find and Replace to do that in my knowledge, unless you prove me I'm wrong.

I'll be happy to be wrong!

Thanks anyway,

boloco

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 25, 2009 Jun 25, 2009

www.DwFAQ.info wrote:

Just like with Automator relinking pages in DW is as easy as using find/replace. Open DW, go to find/replace, find .html and replace with .php and there ya go. That's what find/replace is used for isn't it - finding and replacing things

Sure, but if you use that sledgehammer approach, you'll convert every external link that ends in .html, too. It's not quite as straightforward as you seem to think.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 25, 2009 Jun 25, 2009

I knew you'd say something like that because surely it would be too hard to find your_page.html, your_other_page.html, etc. and replace to your_page.php etc. to only change your page extensions from html to php and retain extension for other links. Or alternatively it would be too difficult to change extensions then go and patch outside links that may have been replaced. You can also use a regular expression to avoid replacing unwanted extensions. It's actually a lot easier than you would think. No you're right just go and manually change all the 100+ links yourself that's the fast, efficient way to do it I agree.

boloco,

To use find/replace in DW go to find/replace from the View menu (command F)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 26, 2009 Jun 26, 2009

You can also use a regular expression to avoid replacing unwanted extensions. It's actually a lot easier than you would think.

If it's so easy, perhaps you would like to provide boloco with the appropriate regular expression to identify external links. It's not impossible, but it would need to be very thoroughly tested before running it through 300 pages. Just telling someone to run Find and Replace on a large number of pages without thinking through the possible consequences is not very helpful.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 26, 2009 Jun 26, 2009

Exactly!

DwFAQ, I would appreciate you provide me the regular expression so I can try it in the future after I test it.

Actually, I'm with David. I'm just doing it patiently one by one with a some breaks so I don't go too crazy.

Thank you both of you for your input.

This question is for David.

David, can I run without downside html files on a dynamic site?

Thanks!

boloco

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 26, 2009 Jun 26, 2009

Certainly, you can run html files on a dynamic site. There are two possible scenarios:

  • The server is configured to treat .html files as .php files.
  • The .html files don't contain any PHP code.

In the first scenario, the server automatically passes all files to the PHP engine. If you're on shared hosting, your hosting company is unlikely to agree to this, but you can certainly ask.

In the second scenario, you can convert your files to .php as and when you add PHP code to a file. The problem with this approach is that URLs bookmarked by others will break each time you change. When creating a PHP site, I always use .php file name extensions, even if the page isn't dynamic, because it allows me to add PHP code at any stage later on.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 26, 2009 Jun 26, 2009

Thanks you much David.

Have a great weekend!

boloco

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 06, 2011 Mar 06, 2011

Thanks!!! I've been on mac forever and never used Automator. Kicks butt. You saved me a ton of copy-paste. AND, it was done in about .5 seconds.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 07, 2011 Mar 07, 2011
LATEST

Good discussion! I admit my first thought was that it should be easy to ID external links in the source, but after about 2 seconds, I realized otherwise. While they start with HTTP, they could end in just about anything - so searching for something that begins with this ends with that is out, even if the Find and Replace dialog allowed you to do that.

I make every page PHP now, if for nothing other than a menu include.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines