ultrus Posted August 14, 2008 Share Posted August 14, 2008 Hello, I have php documents that use spaces to indent the code, and am planning on using Dreamweaver's find and replace tool with regular expressions to replace the spaces with tabs. How would I find \n following any number of spaces with \n and number of tabs? I don't want to replace all spaces in the document with tabs of course. (If the answer is in php script, that's fine with me) Thanks for the assist! Quote Link to comment Share on other sites More sharing options...
effigy Posted August 14, 2008 Share Posted August 14, 2008 <pre> <?php ### Space = #32; Tab = #9. ### How many spaces is a tab? $tab = 8; $data = <<<DATA 2 4 6 8 10 12 14 16 DATA; echo preg_replace('/[ \t]/', 'X', $data), '<br>'; print_r(count_chars($data, 1)); echo '<hr>'; $data = preg_replace('/^([ ]+)/me', 'str_repeat("\t", strlen("$1") / $tab)', $data); echo preg_replace('/[ \t]/', 'X', $data), '<br>'; print_r(count_chars($data, 1)); ?> </pre> XX2 XXXX4 XXXXXX6 XXXXXXXX8 XXXXXXXXXX10 XXXXXXXXXXXX12 XXXXXXXXXXXXXX14 XXXXXXXXXXXXXXXX16 Array ( [10] => 7 [13] => 7 [32] => 72 [48] => 1 [49] => 4 [50] => 2 [52] => 2 [54] => 2 [56] => 1 ) ------------------------------------------- 2 4 6 X8 X10 X12 X14 XX16 Array ( [9] => 6 [10] => 7 [13] => 7 [48] => 1 [49] => 4 [50] => 2 [52] => 2 [54] => 2 [56] => 1 ) Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted August 14, 2008 Share Posted August 14, 2008 Hello, I have php documents that use spaces to indent the code, and am planning on using Dreamweaver's find and replace tool with regular expressions to replace the spaces with tabs. How would I find \n following any number of spaces with \n and number of tabs? I don't want to replace all spaces in the document with tabs of course. (If the answer is in php script, that's fine with me) Thanks for the assist! In Dreamweaver, from the top menu, select Edit > Preferences... In the left category column, scroll down till you see 'code format', click on it.. in the right hand panel, you should see at the top an indent with a checkmark, followed by a number field and a dropdown menu (the default will most likely be 2 in the field and the dropdown set to spaces).. set the field to 1, and set the dropdown to tabs. Click 'OK'. Finally, in the top menu, select Commands > Apply Source Formatting. Done. Cheers, NRG Quote Link to comment Share on other sites More sharing options...
ultrus Posted August 14, 2008 Author Share Posted August 14, 2008 nice! Both of those work. I actually did a folder-wide search and replace of double space to dingle tab, since I never used a double space anywhere except for indenting. Now everything is tabbed out. Thanks! Quote Link to comment 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.