note 114415 added to function.str-replace

From: Date: Tue, 18 Feb 2014 08:59:24 +0000
Subject: note 114415 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-198540@lists.php.net to get a copy of this message
I have: <?php function lacz_bd() { $db = new mysqli('localhost', '_admin', 'pass', 'db'); if (! $db) return false; $db->autocommit(TRUE); return $db; } // dane do ramy pliku .xml $kanalRSS = '<?xml version="1.0" encoding="ISO-8859-2"?>'; $kanalRSS .= '<trovit>'; $kanalRSS .= '<ad>'; // połaczenie z bazą danych $db = lacz_bd(); //zapytanie określające dane ktore powinny byc pobrane z tabeli // teraz pobierzmy wszystkie dane spelniajace warunek category_id=140 $zapytanie = "SELECT * FROM announcements WHERE category_id in (140,141,142,143,144)"; $wynik = $db->query($zapytanie); $ile_znalezionych = $wynik->num_rows; for ($i=0; $i <$ile_znalezionych; $i++) { $wiersz = $wynik->fetch_assoc(); //usuwamy znaczniki html ze wszystkich danych z tabeli, polskie znaki, duze litery $string_title = $wiersz['annoucement_title']; $string_url = $wiersz['annoucement_title']; $pattern = array(' ', ',', '.', '/ą/', '/Ą/', '/ć/', '/Ć/', '/ę/', '/Ę/', '/ł/', '/Ł/' ,'/ń/', '/Ń/', '/ó/', '/Ó/', '/ś/', '/Ś/', '/ź/', '/Ź/', '/ż/', '/Ż/',); $replacement = array('-', '', '', 'a', 'A', 'c', 'C', 'e', 'E', 'l', 'L', 'n', 'N', 'o', 'O', 's', 'S', 'z', 'Z', 'z', 'Z',); $string_url = strtolower(str_replace($pattern, $replacement, $string_url)); $wiersz['annoucement_content'] = strip_tags($wiersz['annoucement_content']); //dodajemy nazwy rodzajow ogloszenia $string_type = $wiersz['annoucement_type']; $_type = array('1', '2', '3', '4'); $_new_type = array('Buy', 'Replace', 'For Rent', 'For Sale'); $wiersz['annoucement_type'] = str_replace($_type, $_new_type, $string_type); //tutaj generujemy zawartosc pliku .xml, ktora pobierana jest z tabeli announcements $kanalRSS .= '<item>'; $kanalRSS .= '<id><![CDATA['.$wiersz['annoucement_id'].']]></id>'; $kanalRSS .= '<url><![CDATA[http://oglaszajtu.pl/ogloszenia/'.$wiersz['annoucement_id'].'/'.$string_url.']]></url>'; $kanalRSS .= '<title><![CDATA['.$string_title.']]></title>'; $kanalRSS .= '<type><![CDATA['.$wiersz['annoucement_type'].']]></type>'; $kanalRSS .= '<content><![CDATA['.$wiersz['annoucement_content'].']]></content>'; $kanalRSS .= '<date><![CDATA['.$wiersz['annoucement_date_added'].']]></date>'; $kanalRSS .= '</item>'; } $kanalRSS .= ' </ad>'; $kanalRSS .= '</trovit>'; //Zapisujemy wygenerowany kod XML do pliku moj_rss.xml $fp = fopen('trovit_oglaszajtu.xml','w'); fwrite($fp,$kanalRSS); fclose($fp); ?> And one problem - ą,ó,ś, etc - don't delete oglaszajtu.pl/moj_rss.php oglaszajtu.pl/trovit_oglaszajtu.xml :-( Can anyone help me? Thx rel ---- Server IP: 46.17.113.2 Probable Submitter: 78.133.136.230 ---- Manual Page -- http://php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/114415 Del: integrated -- https://master.php.net/note/delete/114415/integrated Del: useless -- https://master.php.net/note/delete/114415/useless Del: bad code -- https://master.php.net/note/delete/114415/bad+code Del: spam -- https://master.php.net/note/delete/114415/spam Del: non-english -- https://master.php.net/note/delete/114415/non-english Del: in docs -- https://master.php.net/note/delete/114415/in+docs Del: other reasons-- https://master.php.net/note/delete/114415 Reject -- https://master.php.net/note/reject/114415 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198540) next »