Remove Spaces(PHP)

Advert test
#1
I have source code thats generated by php then stored in a variable and echoed out. I want to remove the whitespace at the begining of every line but unsure how to go about it, any ideas?
Code:
<?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
        <title>Site</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="robots" content="noindex,nofollow" />
        <meta name="googlebot" content="noarchive" />
 

louie

New Member
#5
PHP:
$var = trim($var); // should do the trick removing white spaces at the beginning & end of the string
 
//another option is preg_replace - but removes anything that you are telling it to... (in this case white spaces...)
 
$var = preg_replace("#\s+#","",$var);
 
Top