{"id":77,"date":"2023-09-28T12:11:35","date_gmt":"2023-09-28T10:11:35","guid":{"rendered":"https:\/\/mes-astuces-web.com\/?page_id=77"},"modified":"2024-01-05T16:34:20","modified_gmt":"2024-01-05T15:34:20","slug":"php","status":"publish","type":"page","link":"https:\/\/mes-astuces-web.com\/?page_id=77","title":{"rendered":"PHP"},"content":{"rendered":"\n<p class=\"has-white-background-color has-background wp-block-paragraph\" style=\"padding-top:var(--wp--preset--spacing--50);padding-right:var(--wp--preset--spacing--50);padding-bottom:var(--wp--preset--spacing--50);padding-left:var(--wp--preset--spacing--50)\"><em><strong>Comment convertir une date en format fran\u00e7ais sans la fonction obsol\u00e8te strftime en PHP :<\/strong><\/em><br><em>Voici comment j&#8217;ai transform\u00e9 une date du format US en format fran\u00e7ais :<\/em><br>$dateUSfull = date(&#8216;l d F Y&#8217;);<br>$dateFRday = str_replace([&#8216;Monday&#8217;, &#8216;Tuesday&#8217;, &#8216;Wednesday&#8217;, &#8216;Thursday&#8217;, &#8216;Friday&#8217;, &#8216;Saturday&#8217;, &#8216;Sunday&#8217;],[&#8216;Lundi&#8217;, &#8216;Mardi&#8217;, &#8216;Mercredi&#8217;, &#8216;Jeudi&#8217;, &#8216;Vendredi&#8217;, &#8216;Samedi&#8217;, &#8216;Dimanche&#8217;], $dateUSfull);<br>$dateFRfull = str_replace([&#8216;January&#8217;, &#8216;February&#8217;, &#8216;March&#8217;, &#8216;April&#8217;, &#8216;May&#8217;, &#8216;June&#8217;, &#8216;July&#8217;, &#8216;August&#8217;, &#8216;September&#8217;, &#8216;October&#8217;, &#8216;November&#8217;, &#8216;December&#8217;], [&#8216;Janvier&#8217;, &#8216;F\u00e9vrier&#8217;, &#8216;Mars&#8217;, &#8216;Avril&#8217;, &#8216;Mai&#8217;, &#8216;Juin&#8217;, &#8216;Juillet&#8217;, &#8216;Ao\u00fbt&#8217;, &#8216;Septembre&#8217;, &#8216;Octobre&#8217;, &#8216;Novembre&#8217;, &#8216;D\u00e9cembre&#8217;], $dateFRday);<br>echo $dateFRfull;<br>R\u00e9sultat : Tuesday 15 August 2023 =&gt; Mardi 15 Ao\u00fbt 2023<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"has-white-background-color has-background wp-block-paragraph\"><strong><em>Comment rendre une page d&#8217;une navigation &#8216;active&#8217; en PHP :<\/em><\/strong><br><em>Voici comment j&#8217;ai rendu une page d&#8217;une navigation active :<\/em><br>&lt;ul class=&#8221;menu&#8221;&gt;<br>&lt;?php $page = $_SERVER[&#8216;PHP_SELF&#8217;]; ?&gt;<br>&lt;li class=&#8221;&lt;?php if (basename($page) == &#8220;index.php&#8221;) {echo &#8216;bold&#8217;;} ?&gt;&#8221;&gt;&lt;a class=&#8221;link_pages&#8221; href=&#8221;index.php&#8221;&gt;Accueil&lt;\/a&gt;&lt;\/li&gt;<br><em>idem autres &lt;li&gt;<\/em><br><em>idem autres &lt;li&gt;<\/em><br><em>idem autres &lt;li&gt;<\/em><br>&lt;\/u&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"has-text-align-left has-white-background-color has-background wp-block-paragraph\"><strong><em>Pagination avec un array :<\/em><\/strong><br>Voici comment j&#8217;ai cr\u00e9\u00e9 une pagination en PHP avec une requ\u00eate SQL :<br>&lt;?php<br>try&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp; require&nbsp;&#8220;.\/constants\/pdo.php&#8221;;<br><br>$nbmatch = $statement-&gt;fetchAll();&nbsp;$statement = $pdo-&gt;query(&#8216;SELECT&nbsp;*&nbsp;FROM&nbsp;matchs&nbsp;WHERE&nbsp;match_status&nbsp;=&nbsp;&#8220;termin\u00e9&#8221;&nbsp;ORDER BY&nbsp;match_date&nbsp;ASC, start_time&nbsp;&nbsp;ASC&#8217;, PDO::FETCH_ASSOC);<br><br>$nbmatch = $statement-&gt;fetchAll();<br>$count = count($nbmatch);<br>$itemsPerPage =&nbsp;10;<br>$nbPages = ceil($count \/ $itemsPerPage);<br><br>if&nbsp;($count &lt;&nbsp;10) {<br>foreach&nbsp;($pdo-&gt;query(&#8216;SELECT&nbsp;*&nbsp;FROM&nbsp;matchs&nbsp;WHERE&nbsp;match_status&nbsp;=&nbsp;&#8220;termin\u00e9&#8221;&nbsp;ORDER BY&nbsp;match_date&nbsp;DESC,&nbsp; &nbsp; &nbsp; &nbsp; start_time&nbsp;DESC&#8217;, PDO::FETCH_ASSOC) as $match_name) {<br><br>                                 VOTRE AFFICHAGE<br>}<br>}&nbsp;else&nbsp;{<br>   if&nbsp;(isset($_GET[&#8220;page&#8221;]))&nbsp;<br>        $currentPage = $_GET[&#8220;page&#8221;];<br>        $limitX = ($currentPage * $itemsPerPage) &#8211;&nbsp;10;<br>        $limitY = $itemsPerPage &#8211;&nbsp;1;<br><br>foreach&nbsp;($pdo-&gt;query(&#8216;SELECT&nbsp;*&nbsp;FROM&nbsp;matchs&nbsp;WHERE&nbsp;match_status&nbsp;=&nbsp;&#8220;termin\u00e9&#8221;&nbsp;ORDER BY&nbsp;match_date&nbsp;DESC, start_time&nbsp;DESC&nbsp;LIMIT&nbsp;&#8216;&nbsp;. $limitX .&nbsp;&#8216;, &#8216;&nbsp;. $limitY .&nbsp;&#8221;, PDO::FETCH_ASSOC) as $match_name)&nbsp;<br><br>                                 VOTRE AFFICHAGE&nbsp;<br>} ?&gt;<br>&lt;ul&nbsp;class=&#8221;pages_li&#8221;&gt;&nbsp;<br>&lt;li&gt;<br>Page&nbsp;&lt;a&nbsp;class=&#8221;pages_liens&nbsp;&lt;?php&nbsp;if&nbsp;(!isset($currentPage)) {echo&nbsp;&#8216;bold&#8217;;}&nbsp;?&gt;&#8221;&nbsp; href=&#8221;matchs_over.php&#8221;&gt;1 &amp;nbsp&lt;\/a&gt;<br>&lt;\/li&gt;<br><br>&lt;?php<br>for&nbsp;($i =&nbsp;2; $i &lt;= $nbPages; $i++) {&nbsp;?&gt;<br>&lt;li&nbsp;class=&#8221;&lt;?php&nbsp;if&nbsp;(htmlentities($currentPage) == $i) {echo&nbsp;&#8216;bold&#8217;;}&nbsp;?&gt;&#8221;&gt;<br>&lt;a&nbsp;class=&#8221;pages_liens&#8221;&nbsp;href=&#8217;matchs_over.php?page=&lt;?php&nbsp;echo $i;&nbsp;?&gt;&#8217;&gt;&lt;?php&nbsp;echo $i;&nbsp;?&gt;&nbsp; &amp;nbsp&lt;\/a&gt;<br>&lt;\/li&gt;<br>&lt;?php&nbsp;}&nbsp;?&gt;<br>&lt;li&gt;&amp;nbsp &amp;nbsp &amp;nbsp &amp;nbsp &amp;nbsp&lt;\/li&gt;&nbsp;&lt;?php<br>echo&nbsp;&#8216;&lt;\/ul&gt;&#8217;;<br>echo&nbsp;&#8216;&lt;br&gt;&#8217;;<br><br>}&nbsp;else&nbsp;{<br>foreach&nbsp;($pdo-&gt;query(&#8216;SELECT&nbsp;*&nbsp;FROM&nbsp;matchs&nbsp;WHERE&nbsp;match_status&nbsp;=&nbsp;&#8220;termin\u00e9&#8221;&nbsp;ORDER BY&nbsp;match_date&nbsp; &nbsp;&nbsp;&nbsp;DESC, start_time&nbsp;DESC&nbsp;LIMIT&nbsp;0,&nbsp;10&#8217;, PDO::FETCH_ASSOC) as $match_name) {<br><br>                                       VOTRE AFFICHAGE<br>&nbsp;}&nbsp;?&gt;<br>&lt;ul&nbsp;class=&#8221;pages_li&#8221;&gt;<br>&nbsp;&lt;li&gt;<br>Page&nbsp;&lt;a&nbsp;class=&#8221;pages_liens&nbsp;&lt;?php&nbsp;if&nbsp;(!isset($currentPage)) {echo&nbsp;&#8216;bold&#8217;;}&nbsp;?&gt;&#8221;&nbsp; href=&#8221;matchs_over.php&#8221;&gt;1 &amp;nbsp&lt;\/a&gt;<br>&lt;\/li&gt;<br><br>&lt;?php<br>&nbsp;&nbsp;for&nbsp;($i =&nbsp;2; $i &lt;= $nbPages; $i++) {&nbsp;?&gt;<br>&lt;li&nbsp;class=&#8221;&lt;?php&nbsp;if&nbsp;(htmlentities($currentPage) == $i) {echo&nbsp;&#8216;bold&#8217;;}&nbsp;?&gt;&#8221;&gt;<br>&lt;a&nbsp;class=&#8221;pages_liens&#8221;&nbsp;href=&#8217;matchs_over.php?page=&lt;?php&nbsp;echo $i;&nbsp;?&gt;&#8217;&gt;&lt;?php&nbsp;echo $i;&nbsp;?&gt;&nbsp; &amp;nbsp&lt;\/a&gt;<br>&lt;\/li&gt;<br>&nbsp;&lt;?php&nbsp;}&nbsp;?&gt;<br>&lt;li&gt;&amp;nbsp &amp;nbsp &amp;nbsp &amp;nbsp &amp;nbsp&lt;\/li&gt;&nbsp;&lt;?php<br>&nbsp;echo&nbsp;&#8216;&lt;\/ul&gt;&#8217;;<br>echo&nbsp;&#8216;&lt;br&gt;&#8217;;<br>&nbsp;      }<br>&nbsp;   }<br>&nbsp;}&nbsp;catch&nbsp;(PDOException $e) {<br>&nbsp;echo&nbsp;&#8216;pb de connexion&#8217;;<br>&nbsp;}<br>?&gt;<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"has-white-background-color has-background wp-block-paragraph\"><strong><em>Probl\u00e8me d&#8217;affichage des accents&nbsp;des donn\u00e9es de la base de donn\u00e9es&nbsp;(solution trouv\u00e9e dans le forum Planethoster) :<\/em><\/strong><br>S\u00e9lectionner l&#8217;interclassement utf8mb4_unicode_ci et rajouter en dernier de votre instance PDO le param\u00e8tre &#8220;array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt;&nbsp;&#8220;SET NAMES utf8&#8221; :<br><br>$pdo =&nbsp;new&nbsp;PDO(&#8216;mysql:host=localhost; dbname=bdd_name&#8217;,&nbsp;&#8216;username&#8217;,&nbsp;&#8216;pswd&#8217;, array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt;&nbsp;&#8220;SET NAMES utf8&#8221;));<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0\u00a0<\/p>\n\n\n\n<p class=\"has-white-background-color has-background wp-block-paragraph\"><strong><em>Probl\u00e8me d&#8217;affichage des accents en PHP :<\/em><\/strong><br><br>1) Pour retirer des caract\u00e8res sp\u00e9ciaux incluant le signe &#8216;=&#8217;, utiliser la fonction <strong>quoted_printable_decode<\/strong> :<br>$texte_converti1 = quoted_printable_decode($texte_a_convertir);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<br>2) Pour retirer des caract\u00e8res sp\u00e9ciaux incluant le signe &#8216;?&#8217;, utiliser la fonction <strong>iconv<\/strong> :<br>$texte_converti2 = iconv(&#8220;iso-8859-1&#8221;, &#8220;UTF-8&#8221;, $texte_a_convertir);<br><em>NB : pour conna\u00eetre le charset du texte d&#8217;un email, utliser la fonction imap_fetchheader($connection_imap, $email_number)<\/em><br><br>Les deux peuvent se cumuler.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Comment convertir une date en format fran\u00e7ais sans la fonction obsol\u00e8te strftime en PHP :Voici comment j&#8217;ai transform\u00e9 une date du format US en format fran\u00e7ais :$dateUSfull = date(&#8216;l d F Y&#8217;);$dateFRday = str_replace([&#8216;Monday&#8217;, &#8216;Tuesday&#8217;, &#8216;Wednesday&#8217;, &#8216;Thursday&#8217;, &#8216;Friday&#8217;, &#8216;Saturday&#8217;, &#8216;Sunday&#8217;],[&#8216;Lundi&#8217;, &#8216;Mardi&#8217;, &#8216;Mercredi&#8217;, &#8216;Jeudi&#8217;, &#8216;Vendredi&#8217;, &#8216;Samedi&#8217;, &#8216;Dimanche&#8217;], $dateUSfull);$dateFRfull = str_replace([&#8216;January&#8217;, &#8216;February&#8217;, &#8216;March&#8217;, &#8216;April&#8217;, &#8216;May&#8217;, &#8216;June&#8217;, &#8216;July&#8217;,&hellip; <a class=\"more-link\" href=\"https:\/\/mes-astuces-web.com\/?page_id=77\">Continue reading <span class=\"screen-reader-text\">PHP<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":15,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-77","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/mes-astuces-web.com\/index.php?rest_route=\/wp\/v2\/pages\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mes-astuces-web.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mes-astuces-web.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mes-astuces-web.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mes-astuces-web.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=77"}],"version-history":[{"count":13,"href":"https:\/\/mes-astuces-web.com\/index.php?rest_route=\/wp\/v2\/pages\/77\/revisions"}],"predecessor-version":[{"id":158,"href":"https:\/\/mes-astuces-web.com\/index.php?rest_route=\/wp\/v2\/pages\/77\/revisions\/158"}],"up":[{"embeddable":true,"href":"https:\/\/mes-astuces-web.com\/index.php?rest_route=\/wp\/v2\/pages\/15"}],"wp:attachment":[{"href":"https:\/\/mes-astuces-web.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}