1. i have a question about using header("Location: filename.html"); in php with my present code i have a few echo statements followed by header("Location: filename.html"); because i have echo statements before header("Location: filename.html"); i am getting an error that headers have already been sent. i cannot remove the echo statements as they are doing an important task. based on this situation i can use echo followed by the html code for the filename in filename.html if i do this the code will run into a few 100's of lines and due to this i would like to use header("Location: filename.html"); i have tried the following code and it works = echo " <form name='errorpage' action='error.php' method='post'> </form> <script type='text/javascript' language='javascript'> document.errorpage.submit(); </script> "; however if javascript is turned off this redirection will not work. could you please suggest if there is an alternative to using echo statement first followed by header("Location: filename.html"); 2. i am using the following php validation for forms which is not working very well a) $specialcharacters = '#^([a-zA-Z0-9]+)$#'; with this code for a name if i type "first name" with a space it is considering the space and treating as a special character however it should validate for letters and numbers only. how can i write '/^[a-zA-Z]+$/'; to ignore spaces b) $firstnamecheck = '/^[a-zA-Z]+$/'; with this code if i type for example "first name" as per the error is states that the string needs to contain letters. though i typed letters because of the space it is not treating as letters. how can i rewrite this '/^[a-zA-Z]+$/'; please advice. thanks.
1) Using header() to redirect will do it instantly and because it modifies the headers, you cannot print any text/html before you attempt to do it. What important task does echoing have that it has to be before the header redirect? If you're trying to redirect using header then you can't possibly have any text first. If you really really need to print text to the page and still want to redirect, try using meta refresh: <meta http-equiv='refresh' content='#;url=filename.html'> HTML: where you would replace # with the number of seconds you want it to wait after the page fully loads to redirect (can use 0 to redirect right away but it waits until everything fully loads). 2) If you want it to count spaces too, simply put a space in your square brackets []. Example: [a-zA-Z ] Small note: if you don't care if it's capitalized or lowercase, instead of putting both a-z and A-Z in the brackets, you could put an i (which means case-insensitive) after your match delimeter (# in your first match string and / in your second). So your first one would be, with allowing spaces and not caring about case: $specialcharacters = '#^([a-z0-9 ]+)$#i'; PHP: