Remove Test Code Quickly with a Simple Dreamweaver Search
Adding test code throughout your scripts may be necessary for troubleshooting or adding new features, but how do you go about removing the code? In a previous post, a few techniques for locating the blocks of test code were discussed, but the code still needs to manually removed. Instead, let's tap into Dreamweaver's search for HTML tag feature.
Previously (Making It Easy to Locate and Remove Test Code), comments were utilized for locating our test code.
<p>Our current projects include</p>
<?php print $currentProjects; ?>
<?php
//TEST code; remove when done-------------
var_dump($currentProjects);
//----------------------------------------
?>
As long as the comments are labeled the same, a quick search could be performed to find them all. The problem is that this method requires us to manually remove the code. That's where Dreamweaver's ability to search for specific tags could be handy. First, the test code needs to be enclosed within an HTML tag.
<p>Our current projects include</p>
<?php print $currentProjects; ?>
<span class="testCode">
<?php
//TEST code; remove when done-------------
var_dump($currentProjects);
//----------------------------------------
?>
</span>
Note: the <span> tag was used because of its minimal effect to the page. Under normal circumstances, the tag doesn't add line breaks or some other alteration which messes with the page flow. Of course, I am aware that the results from var_dump() may be very noticeable.
Remove Test Code
When the testing phase is over, the code blocks can be removed as follows:
- Open the document containing the modified test code
- Open the Find and Replace dialog box (Ctrl + F)
- Under the Search drop-down, choose Specific Tag (see Figure 1)
- Enter span as the tag (see Figure 2)
- For the With Attribute option, enter class = testCode (see Figure 3)
- For the Action, choose Remove Tag & Contents (see Figure 4)
- Find and replace the blocks of test code
Note that you may want to watch the removal process carefully so that it doesn't do anything unexpected.

Figure 1. Select the Specific Tag Option

Figure 2. Indicate the HTML Tag Name

Figure 3. Set the Attribute Name and Value

Figure 4. Select the Remove Tag & Contents Option
Potential Issues
Unfortunately, Dreamweaver doesn't recognize the HTML tags entered within blocks of PHP code.
<?php
//...
$today = date('Y-m-d');
print '<span class="testCode">';
//TEST code; remove when done-------------
$today = $_GET['today'];
//----------------------------------------
print '</span>';
$sql = "SELECT fields FROM table WHERE date>='$today'";
//...
?>
To add the HTML tag, the PHP code block needs to be split up temporarily.
<?php
//...
$today = date('Y-m-d');
?>
<span class="testCode">
<?php
//TEST code; remove when done-------------
$today = $_GET['today'];
//----------------------------------------
?>
</span>
<?php
$sql = "SELECT fields FROM table WHERE date>='$today'";
//...
?>
Note: a portion of the split will be left behind after the Dreamweaver search; that part needs to be removed manually.
Other issues may arise based on where the test code is placed. For example, if the code appears before the
Conclusion
Although this isn't the perfect solution, it at least gets us closer. Less time will be spent on manually removing code and the potential of missing a portion of the code is reduced.
0 Comments
There are currently no comments.
Leave a Comment