Cibiņš Posted February 25, 2012 Report Share Posted February 25, 2012 Sveiki kolēģi! Tātad ieskrēju ar problēmu - tādu problēmu, ka teksta beigās liek mistisku speisu jeb " ". Mēģināju ar str_replace novākt bet tad iebāž "-", rotams speisos biju paredzējis likt tos mīnusus bet nu nejau teksta beigās! Respektīvi ja ierakstu formā vārdu "Mani sauc Cibins" tad izvada "mani-sauc-cibins-" bet to "-" beigās nahren nevajag! Kā lai aizvāc? Kā lai padod lai to MĪNUSU neliek teksta beigās? Protams šeit padodot vērtību ir jānovāc visi tagi, visi liekie simboli, ļaujot tekstu sadalīt ar mīnusa zīmēm. $remove_tags = str_replace($from_field); $fixpound= str_replace("£", "£", $remove_tags); $fixeur = str_replace("€", "€", $fixpound); $remove_symbols = preg_replace("/[^a-zA-Z0-9\s\.\/:!\[\]\*\+\-\|\<\>@#\$%\^&\(\)_=\';,'\?\\\{\}`~\"]/", '', $fixeur); $lowercase = strtolower($remove_symbols); $olddata=array(' ',' '); $newdata=array('-','-'); $replace_spaces = str_replace($olddata, $newdata, $lowercase); Quote Link to comment Share on other sites More sharing options...
marrtins Posted February 25, 2012 Report Share Posted February 25, 2012 (edited) Priekš kā ir šīs rindas? $remove_tags = str_replace($from_field); $fixpound= str_replace("£", "£", $remove_tags); $fixeur = str_replace("€", "€", $fixpound); Šo $olddata=array(' ',' '); $newdata=array('-','-'); $replace_spaces = str_replace($olddata, $newdata, $lowercase); var aizstāt ar $replace_spaces = str_replace(' ', '-', $lowercase); Pamēģināju - nekādi papildus speisi neveidojas. Varbūt jau saņem datus ar atstarpi beigās? $from_field = trim($from_field); Edited February 25, 2012 by marrtins Quote Link to comment Share on other sites More sharing options...
Cibiņš Posted February 25, 2012 Author Report Share Posted February 25, 2012 (edited) Priekš kā ir šīs rindas? $remove_tags = str_replace($from_field); $fixpound= str_replace("£", "£", $remove_tags); $fixeur = str_replace("€", "€", $fixpound); Šo $olddata=array(' ',' '); $newdata=array('-','-'); $replace_spaces = str_replace($olddata, $newdata, $lowercase); var aizstāt ar $replace_spaces = str_replace(' ', '-', $lowercase); Pamēģināju - nekādi papildus speisi neveidojas. Varbūt jau saņem datus ar atstarpi beigās? $from_field = trim($from_field); Sorry nolažojos, kad teksts ir piemēŗam šāds "Mani sauc Cibins €" vai kad ieliek kautkur neatļautus simbolus - copyright, euro, pound utt tad euro vietā veidojas mistisks space. Reāli nezinu kā lai aizvieto teksta beigās vai pa vidu neatļauto simbolu speisus.. Edited February 25, 2012 by Cibiņš Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted February 25, 2012 Report Share Posted February 25, 2012 (edited) trim($str, '-'); Edited February 25, 2012 by rATRIJS Quote Link to comment Share on other sites More sharing options...
marrtins Posted February 25, 2012 Report Share Posted February 25, 2012 (edited) Nu tad tas superkods varētu būt šāds: $from_field = 'Mani sauc Cibins €'; //$remove_tags = str_replace($from_field); $remove_tags = $from_field; $fixpound= str_replace("£", "£", $remove_tags); $fixeur = str_replace("€", "€", $fixpound); $remove_symbols = preg_replace("/[^a-zA-Z0-9\s\.\/:!\[\]\*\+\-\|\<\>@#\$%\^&\(\)_=\';,'\?\\\{\}`~\"]/", '', $fixeur); $lowercase = strtolower($remove_symbols); //$olddata=array(' ',' '); //$newdata=array('-','-'); //$replace_spaces = str_replace($olddata, $newdata, $lowercase); $lowercase = trim($lowercase); $replace_spaces = str_replace(' ', '-', $lowercase); print "'$replace_spaces'\n"; Es gan pats izmantoju šādu kods: function urlize($name) { $name = preg_replace("/[%]/", " ", $name); $name = html_entity_decode($name, ENT_QUOTES, "UTF-8"); $name = mb_strtolower($name); $name = strip_tags($name); $name = preg_replace("/[\:\/\?\#\[\]\@\"'\(\)\.,&;\+=\\\]/", " ", $name); $name = trim($name); $name = preg_replace("/\s+/", "-", $name); $name = preg_replace("/-+/", "-", $name); return $name; } // urlize Edited February 25, 2012 by marrtins Quote Link to comment Share on other sites More sharing options...
Cibiņš Posted February 25, 2012 Author Report Share Posted February 25, 2012 Nu tad tas superkods varētu būt šāds: $from_field = 'Mani sauc Cibins €'; //$remove_tags = str_replace($from_field); $remove_tags = $from_field; $fixpound= str_replace("£", "£", $remove_tags); $fixeur = str_replace("€", "€", $fixpound); $remove_symbols = preg_replace("/[^a-zA-Z0-9\s\.\/:!\[\]\*\+\-\|\<\>@#\$%\^&\(\)_=\';,'\?\\\{\}`~\"]/", '', $fixeur); $lowercase = strtolower($remove_symbols); //$olddata=array(' ',' '); //$newdata=array('-','-'); //$replace_spaces = str_replace($olddata, $newdata, $lowercase); $lowercase = trim($lowercase); $replace_spaces = str_replace(' ', '-', $lowercase); print "'$replace_spaces'\n"; Es gan pats izmantoju šādu kods: function urlize($name) { $name = preg_replace("/[%]/", " ", $name); $name = html_entity_decode($name, ENT_QUOTES, "UTF-8"); $name = mb_strtolower($name); $name = strip_tags($name); $name = preg_replace("/[\:\/\?\#\[\]\@\"'\(\)\.,&;\+=\\\]/", " ", $name); $name = trim($name); $name = preg_replace("/\s+/", "-", $name); $name = preg_replace("/-+/", "-", $name); return $name; } // urlize "Test category 1 pagename €" izvada kā "test-category-1-pagename-"..atkal tas MĪNUSS beigās ir :( $fixpound= str_replace("£", "£", $categories_pagename); $fixeur = str_replace("€", "€", $fixpound); $remove_symbols = preg_replace("/[^a-zA-Z0-9\s\.\/:!\[\]\*\+\-\|\<\>@#\$%\^&\(\)_=\';,'\?\\\{\}`~\"]/", '', $fixeur); $lowercase = strtolower($remove_symbols); $lowercase = trim($lowercase); $replace_spaces = str_replace(' ', '-', $lowercase); $remove_tags=strip_tags($replace_spaces); Quote Link to comment Share on other sites More sharing options...
Cibiņš Posted February 25, 2012 Author Report Share Posted February 25, 2012 (edited) Nē tomēr atkal kad ieliek piem neatļauto eiro simbolu pa vidu, t.i inputs ir "Test category € 1 pagename" izvadās "test-category--1-pagename" :( Bet nobeigumā kā iepriekš bija tā problēma ir atrisināta, beigās vairs tas simbos nav! $fixpound= str_replace("£", "£", $categories_pagename); $fixeur = str_replace("€", "€", $fixpound); $remove_symbols = preg_replace("/[^a-zA-Z0-9\s\.\/:!\[\]\*\+\-\|\<\>@#\$%\^&\(\)_=\';,'\?\\\{\}`~\"]/", '', $fixeur); $lowercase = strtolower($remove_symbols); $lowercase = trim($lowercase); $replace_spaces = str_replace(' ', '-', $lowercase); $remove_tags=strip_tags($replace_spaces); Edited February 25, 2012 by Cibiņš Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.