dingus Posted July 6, 2008 Share Posted July 6, 2008 hey guy i got a problem i just taken over a project from a friend and he has it his code setup like this <?php $test = "some value"; ?> <table> <tr> <td> <?php echo $test ; ?> </td> </tr> </table> now the problem is i need to wrap that in to a single echo any ideas how i would do that (probably some basic regex but idk) Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/ Share on other sites More sharing options...
kenrbnsn Posted July 6, 2008 Share Posted July 6, 2008 Like this: <?php $test = "some value"; echo "<table> <tr> <td>" .$test . " </td> </tr> </table>"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-582897 Share on other sites More sharing options...
dingus Posted July 6, 2008 Author Share Posted July 6, 2008 should have made the question clearer he was writen it like that and the project is well over 500 files its huge and would take me weeks to do it by hand so i was sorta hopeing there was an automated way of doing it Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-582899 Share on other sites More sharing options...
wildteen88 Posted July 6, 2008 Share Posted July 6, 2008 Why do you want to convert it to a single echo? Wouldn't it be best to leave it as-is? You can "go in and out of PHP" as many times within a script, all output doesn't need to be in an echo. Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-582902 Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2008 Share Posted July 6, 2008 You need to post an actual example of what you have and what you are trying to change it to (and state why you are doing this.) Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-582910 Share on other sites More sharing options...
dingus Posted July 7, 2008 Author Share Posted July 7, 2008 ok this is just a basic example this is the origional code <table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin: "> <tr bgcolor="#AFC0D0" valign="top"> <td style="width:33%"> <strong><img src="images/e06.gif" style="width:16; height:9" alt="" border="0">Search for Business in Sydney</strong> <fieldset> <LEGEND></LEGEND> <span><em><strong>1.</strong></em> <strong>Enter Suburbs:</strong></span><br> <input id="tb" name="tb" value="" class="enterSuburb" tabindex="1" onkeyup="javascript:sfsComplete();" type="text"><br> <label class="selectSuburbs"><strong>Or Select Suburbs:</strong></label> <p> <span> <select id="u" name="u" size="5" class="suburbsList" onclick="javascript:sfsInsert();" style="width:75% "> <option selected="selected" value=""> *** SHOW ALL SUBURBS *** </option> <? $query = "SELECT * FROM location ORDER BY `location` ASC "; $result = mysql_query($query); // Determine the number of Users with that name $number = mysql_num_rows($result); if ($number == 0) { echo "<meta http-equiv='Refresh' content='0; URL=index.php'>"; die () ; } else { // Print the employee names for($i=0; $i<$number; $i++){ $Location = mysql_result($result,$i,"Location"); ?> <option value="<? print $Location ; ?>"><? print $Location ; ?></option> <? } } ?> </select> </span> </p> <p> <span class="surroundingSuburbs"><input id="is" name="is" value="1" tabindex="20" type="checkbox"> Include Surrounding Suburbs</span> </p><br> </fieldset></td> <td><img src="images/e03.gif" width="15" height="298" alt="" border="0"></td> <td bgcolor="#D1D6DB" style="width:33%; background-image:url(images/fon01.jpg); background-position: top; background-repeat: repeat-x;"> <strong><img src="images/e06.gif" style="width:16; height:9" alt="" border="0">Search for Business by Category</strong> <fieldset> <LEGEND></LEGEND> <label><em><strong>2.</strong></em> <strong>Enter Category:</strong></label> <span><br> <input id="Type_Category" name="Type_Category" value="" class="enterSuburb" tabindex="1" onkeyup="javascript:Category_sfsComplete();" type="text"></span><br> <label class="selectSuburbs"><strong>Or Select Category:</strong></label> <p> <span> <select id="Select_Category" name="Select_Category" size="5" class="suburbsList" onclick="javascript:Category_sfsInsert();" style="width:75% "> <option> *** Select Category Below *** </option> <? $query = "SELECT * FROM catagory ORDER BY `catagory` ASC"; $result = mysql_query($query); // Determine the number of Users with that name $number = mysql_num_rows($result); if ($number == 0) { echo "<meta http-equiv='Refresh' content='0; URL=index.php'>"; die () ; } else { // Print the employee names for($i=0; $i<$number; $i++){ $catagory = mysql_result($result,$i,"catagory"); ?> <option value="<? print $catagory ; ?>"><? print $catagory ; ?></option> <? } } ?> </select></span> </p> <p> <span class="Allcategorys"><input id="all_Category" name="all_Category" value="1" tabindex="20" type="checkbox"> Select All Category</span> </p><br> </fieldset> <p align="right"><input type="submit" value="search"></p> </td> <td><img src="images/e04.gif" width="14" height="298" alt="" border="0"></td> <td width="33%"><img src="images/px1.gif" width="1" height="1" alt="" border="0"></td> </tr> <tr> <td colspan="5"><img src="images/px1.gif" width="1" height="1" alt="" border="0"></td> </tr> <tr bgcolor="#EE7B10"> <td height="19" colspan="5"><img src="images/px1.gif" width="1" height="1" alt="" border="0"></td> </tr> </table> this is what i want to change it to <?php echo '<table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin: "> <tr bgcolor="#AFC0D0" valign="top"> <td style="width:33%"> <strong><img src="images/e06.gif" style="width:16; height:9" alt="" border="0">Search for Business in Sydney</strong> <fieldset> <LEGEND></LEGEND> <span><em><strong>1.</strong></em> <strong>Enter Suburbs:</strong></span><br> <input id="tb" name="tb" value="" class="enterSuburb" tabindex="1" onkeyup="javascript:sfsComplete();" type="text"><br> <label class="selectSuburbs"><strong>Or Select Suburbs:</strong></label> <p> <span> <select id="u" name="u" size="5" class="suburbsList" onclick="javascript:sfsInsert();" style="width:75% "> <option selected="selected" value=""> *** SHOW ALL SUBURBS *** </option>'; $query = "SELECT * FROM location ORDER BY `location` ASC "; $result = mysql_query($query); // Determine the number of Users with that name $number = mysql_num_rows($result); if ($number == 0) { echo "<meta http-equiv='Refresh' content='0; URL=index.php'>"; die () ; } else { // Print the employee names for($i=0; $i<$number; $i++){ $Location = mysql_result($result,$i,"Location"); echo '<option value="'. $Location .'">'. $Location .'</option>'; } } echo' </select> </span> </p> <p> <span class="surroundingSuburbs"><input id="is" name="is" value="1" tabindex="20" type="checkbox"> Include Surrounding Suburbs</span> </p><br> </fieldset></td> <td><img src="images/e03.gif" width="15" height="298" alt="" border="0"></td> <td bgcolor="#D1D6DB" style="width:33%; background-image:url(images/fon01.jpg); background-position: top; background-repeat: repeat-x;"> <strong><img src="images/e06.gif" style="width:16; height:9" alt="" border="0">Search for Business by Category</strong> <fieldset> <LEGEND></LEGEND> <label><em><strong>2.</strong></em> <strong>Enter Category:</strong></label> <span><br> <input id="Type_Category" name="Type_Category" value="" class="enterSuburb" tabindex="1" onkeyup="javascript:Category_sfsComplete();" type="text"></span><br> <label class="selectSuburbs"><strong>Or Select Category:</strong></label> <p> <span> <select id="Select_Category" name="Select_Category" size="5" class="suburbsList" onclick="javascript:Category_sfsInsert();" style="width:75% "> <option> *** Select Category Below *** </option>'; $query = "SELECT * FROM catagory ORDER BY `catagory` ASC"; $result = mysql_query($query); // Determine the number of Users with that name $number = mysql_num_rows($result); if ($number == 0) { echo "<meta http-equiv='Refresh' content='0; URL=index.php'>"; die () ; } else { // Print the employee names for($i=0; $i<$number; $i++){ $catagory = mysql_result($result,$i,"catagory"); echo' <option value="'. $catagory .'">'. $catagory .'</option>'; } } echo' </select></span> </p> <p> <span class="Allcategorys"><input id="all_Category" name="all_Category" value="1" tabindex="20" type="checkbox"> Select All Category</span> </p><br> </fieldset> <p align="right"><input type="submit" value="search"></p> </td> <td><img src="images/e04.gif" width="14" height="298" alt="" border="0"></td> <td width="33%"><img src="images/px1.gif" width="1" height="1" alt="" border="0"></td> </tr> <tr> <td colspan="5"><img src="images/px1.gif" width="1" height="1" alt="" border="0"></td> </tr> <tr bgcolor="#EE7B10"> <td height="19" colspan="5"><img src="images/px1.gif" width="1" height="1" alt="" border="0"></td> </tr> </table>'; basicly convertting from what was closeing the php tags to putting all the html in an echo statment now for doing the converion i have code to open the files read in the data and write it to the new folder all i need is a a function to accualy convert it Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-583272 Share on other sites More sharing options...
Lodius2000 Posted July 7, 2008 Share Posted July 7, 2008 I still dont see why everything has to be in php Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-583280 Share on other sites More sharing options...
TransmogriBenno Posted July 7, 2008 Share Posted July 7, 2008 I think that's a really bad idea, especially with no reason given. Nevertheless, you can parse PHP source using the PHP tokenizer: http://www.php.net/manual/en/book.tokenizer.php Good luck... Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-583283 Share on other sites More sharing options...
dingus Posted July 7, 2008 Author Share Posted July 7, 2008 well thanks for your help ill read over that but the reasion is because after profileing the code we discovered that openibng and closeing php tags a few 100 times delays exicution Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-583286 Share on other sites More sharing options...
TransmogriBenno Posted July 7, 2008 Share Posted July 7, 2008 Interesting, although I'd have to see your methods to be convinced that your conclusion is correct. Have you tried changing the buffering settings? Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-583288 Share on other sites More sharing options...
wildteen88 Posted July 7, 2008 Share Posted July 7, 2008 From my testing, using single quotes is faster then going in and out of PHP/double quotes. However going in and out of PHP is faster then double quotes. Benchmark script: <?php function timer() { list($usec, $sec) = explode(' ', microtime()); return ((float)$usec + (float)$sec); } $iterations = 1000; $t1 = timer(); echo '<div style="width:250px;height:200px;overflow:auto;margin:10px;border:1px solid #F00;">'; for($i = 0; $i < $iterations; $i++) { ?> Line #<?php echo $i; ?><br /> <?php } echo '</div>'; $t2 = timer(); echo '<div style="width:250px;height:200px;overflow:auto;margin:10px;border:1px solid #F00;">'; for($i = 0; $i < $iterations; $i++) { echo 'Line #' . $i . '<br />'; } echo '</div>'; $t3 = timer(); echo '<div style="width:250px;height:200px;overflow:auto;margin:10px;border:1px solid #F00;">'; for($i = 0; $i < $iterations; $i++) { echo "Line #$i<br />"; } echo '</div>'; $t4 = timer(); $total1 = $t2-$t1; $total2 = $t3-$t2; $total3 = $t4-$t3; $total = $t4-$t1; echo "in-out PHP : $total1 <br />"; echo "in PHP (single quotes) : $total2 <br />"; echo "in PHP (double quotes): $total3 <br /><br />"; echo "Total : $total <br />"; ?> My Results: in-out PHP : 0.0014281272888184 in PHP (single quotes) : 0.0012688636779785 in PHP (double quotes): 0.0019800662994385 Total : 0.0046770572662354 Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-583804 Share on other sites More sharing options...
discomatt Posted July 7, 2008 Share Posted July 7, 2008 IMO the difference is negligible, but by definition, single quotes should be faster. Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-583808 Share on other sites More sharing options...
anon_login_001 Posted July 7, 2008 Share Posted July 7, 2008 The performance difference is absolutely negligible. (did I spell that right?) Placing all of the HTML into strings not only becomes a maintenance nightmare (costs more money to "own", because it takes more time to fix [time=money]). Also, you run into memory/string handling stuff... If you're having performance issues "going in and out of PHP" then it's time to look into using a Cache mechanism, because the other gains are not worth your time. You will acheive *vastly greater results* looking into other means of optimization. (Cache on PHP, Cache on Database information, Query Optimization, etc). Please, please, I beg you not to put all of that HTML into strings. Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-583992 Share on other sites More sharing options...
Stephen Posted July 7, 2008 Share Posted July 7, 2008 I changed over 2300 lines of ?> html <?php to echo fast, so why can't you do 500 files? (100lines ea. would be 5000 lines). Anyway, if its super huge I would think it's fine the way it is. I just switched mine for looks. Quote Link to comment https://forums.phpfreaks.com/topic/113443-html-to-echo/#findComment-583995 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.