Any suggestion on how to extract into separate files php code and html from a source file which is sprinkled with both.
4 Answers
There is no silver bullet, you could choose to view the webpage, view source, save it, then edit that file with placeholders and write new PHP code to replace the place holders with what you want.
But some people will argue that PHP is a templating language, and it should be intermixed. I don't use it that way, but they are correct.
6 Comments
noopize
My question is how to seperate the code from an exisitng project not how to write new code. Is there such a plugin in a text editor for example to seperate automaticaly
Byron Whitlock
+1 @noopize Reread his answer. You need to get the generated html and add php placeholders where dynamic content goes. This is not possible to do automatically.
Francisco Soto
@noopize Well, you can hire a programmer to do it for you, thats the closest to automagically that you can go. :P
noopize
ok I understand the reply now however some cases it is not convinient to run the code to extract from a web page view. I was thinking if there was some sort regex or thing to select all text beinging with <php? and ending ?> and save to file. And begineer programmers will rather do it them selfs :)
user229044
@noopize That can't possibly work. In the cases where PHP and HTML are intermixed, both parts matter. You can't just pull out all the PHP and expect the results to make sense. You'd be better off converting every instance of
?>...<?php to echo "..."; but that's still not going to work most of the time. |