Any suggestion on how to extract into separate files php code and html from a source file which is sprinkled with both.
+2
A:
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.
TravisO
2010-04-28 19:00:34
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
noopize
2010-04-28 19:07:15
+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.
Byron Whitlock
2010-04-28 19:13:31
@noopize Well, you can hire a programmer to do it for you, thats the closest to automagically that you can go. :P
Francisco Soto
2010-04-28 19:14:34
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 :)
noopize
2010-04-28 19:24:30
@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.
meagar
2010-04-28 21:01:34
@noopize There's a reason I said "there is no silver bullet", my comment really did answer you.
TravisO
2010-04-29 22:45:59
+1
A:
No way to do it automatically.
That's what programmers are for ;)
Byron Whitlock
2010-04-28 19:11:46
+1
A:
Well, you could always look for the PHP tags in the file and split using them?
<?php and ?>
Jamza
2010-04-28 20:54:15
A:
You can use any language or application with text precessing capabilities (perl, or python my favorite) and find the tags. After finding the tags you can get the text in between and manipulate it as you like.
biomed
2010-04-28 20:57:15