Jump to content
php.lv forumi

Veido kautkādus mistiskus speisus un ieliek "-" ko NEVAJAG


Cibiņš

Recommended Posts

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);

Link to comment
Share on other sites

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 by marrtins
Link to comment
Share on other sites

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 by Cibiņš
Link to comment
Share on other sites

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 by marrtins
Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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 by Cibiņš
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...