{"id":190,"date":"2008-04-23T19:45:00","date_gmt":"2008-04-23T22:45:00","guid":{"rendered":"http:\/\/helbertt.16mb.com\/site\/index.php\/2008\/04\/23\/eliminar-espacos-com-php\/"},"modified":"2008-04-23T19:45:00","modified_gmt":"2008-04-23T22:45:00","slug":"eliminar-espacos-com-php","status":"publish","type":"post","link":"https:\/\/helbertt.xyz\/site\/eliminar-espacos-com-php\/","title":{"rendered":"Eliminar espa\u00e7os com PHP"},"content":{"rendered":"<p><span style=\"font-family: times new roman;\">A id\u00e9ia \u00e9 eliminar espa\u00e7os extras que os usu\u00e1rios acabam colocando em campos nos nossos formul\u00e1rio, seja um simples \u201cspace\u201d, \u201center\u201d, \u201ctab\u201d e outros\u2026 com esta fun\u00e7\u00e3o e com a ajuda das express\u00f5es regulares, conseguimos resolver isso de forma simples e f\u00e1cil.<\/span><\/p>\n<p><span style=\"font-family: times new roman;\">A fun\u00e7\u00e3o \u00e9 executada em tr\u00eas passos:<\/span><\/p>\n<p><span style=\"font-family: times new roman;\">1. Primeiro utilizamos trim que elimina espa\u00e7os sobrando no in\u00edcio e no final da vari\u00e1vel de dados.<\/span><\/p>\n<p><span style=\"font-family: times new roman;\">2. Depois eliminar espa\u00e7os duplos que pode-se ter dentro dos valores da vari\u00e1vel<\/span><\/p>\n<p><span style=\"font-family: times new roman;\">3. Por \u00faltimo eliminamos tabula\u00e7\u00f5es (t), enter (r) e novas linhas (n) e substituimos por um espa\u00e7o em branco<\/span><\/p>\n<pre style=\"font-family: times new roman;\"><span style=\"color: rgb(0, 0, 0); font-weight: bold;\"><\/span><blockquote><span style=\"color: rgb(0, 0, 0);\">1<\/span><span style=\"color: rgb(0, 0, 0); font-weight: bold;\"> function<\/span> eliminaespaco<span style=\"color: rgb(102, 204, 102);\">(<\/span><span style=\"color: rgb(0, 0, 255);\">$variavel<\/span><span style=\"color: rgb(102, 204, 102);\">)<\/span><span style=\"color: rgb(102, 204, 102);\">{<\/span><br \/>2          <span style=\"color: rgb(0, 0, 255);\">$variavel<\/span> = <span style=\"color: rgb(0, 0, 102);\">trim<\/span><span style=\"color: rgb(102, 204, 102);\">(<\/span><span style=\"color: rgb(0, 0, 255);\">$variavel<\/span><span style=\"color: rgb(102, 204, 102);\">)<\/span>;<br \/>3          <span style=\"color: rgb(0, 0, 255);\">$variavel<\/span> = <span style=\"color: rgb(0, 0, 102);\">preg_replace<\/span><span style=\"color: rgb(102, 204, 102);\">(<\/span><span style=\"color: rgb(255, 0, 0);\">\u2018\/<\/span><span style=\"color: rgb(0, 0, 153); font-weight: bold;\">s<\/span>(?=<span style=\"color: rgb(0, 0, 153); font-weight: bold;\">s<\/span>)\/\u2019, <span style=\"color: rgb(255, 0, 0);\">\u201d<\/span>, <span style=\"color: rgb(0, 0, 255);\">$variavel<\/span><span style=\"color: rgb(102, 204, 102);\">)<\/span>;<br \/>4          <span style=\"color: rgb(0, 0, 255);\">$variavel<\/span> = <span style=\"color: rgb(0, 0, 102);\">preg_replace<\/span><span style=\"color: rgb(102, 204, 102);\">(<\/span><span style=\"color: rgb(255, 0, 0);\">\u2018\/[<\/span><span style=\"color: rgb(0, 0, 153); font-weight: bold;\">n<\/span><span style=\"color: rgb(0, 0, 153); font-weight: bold;\">r<\/span><span style=\"color: rgb(0, 0, 153); font-weight: bold;\">t<\/span>]\/\u2019, <span style=\"color: rgb(255, 0, 0);\">\u2018 \u2018<\/span>, <span style=\"color: rgb(0, 0, 255);\">$variavel<\/span><span style=\"color: rgb(102, 204, 102);\">)<\/span>;<br \/>5          <span style=\"color: rgb(177, 177, 0);\">return<\/span> <span style=\"color: rgb(0, 0, 255);\">$variavel<\/span>;<br \/><span style=\"color: rgb(102, 204, 102);\">6 }<\/span><\/blockquote><span style=\"color: rgb(102, 204, 102);\"><\/span><\/pre>\n<p><span style=\"font-family: times new roman;\">Simples assim. <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A id\u00e9ia \u00e9 eliminar espa\u00e7os extras que os usu\u00e1rios acabam colocando em campos nos nossos formul\u00e1rio, seja um simples \u201cspace\u201d,<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout"},"categories":[93],"tags":[],"_links":{"self":[{"href":"https:\/\/helbertt.xyz\/site\/wp-json\/wp\/v2\/posts\/190"}],"collection":[{"href":"https:\/\/helbertt.xyz\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/helbertt.xyz\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/helbertt.xyz\/site\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/helbertt.xyz\/site\/wp-json\/wp\/v2\/comments?post=190"}],"version-history":[{"count":0,"href":"https:\/\/helbertt.xyz\/site\/wp-json\/wp\/v2\/posts\/190\/revisions"}],"wp:attachment":[{"href":"https:\/\/helbertt.xyz\/site\/wp-json\/wp\/v2\/media?parent=190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/helbertt.xyz\/site\/wp-json\/wp\/v2\/categories?post=190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/helbertt.xyz\/site\/wp-json\/wp\/v2\/tags?post=190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}