Jump to content
php.lv forumi

Ja 2 vai vairāk vienādi "-" blakus, tad atstāt vienu


yeahz

Recommended Posts

-br-----b-notice--b----undefined-index---image-title-in--b-c--appserv-www-switch-mygallery-php--b--on-line--b-174--b--br----43-

 

Kā lai panāk ka izveidojas šādi?

 

br-b-notice-b-undefined-index-image-title-in-b-c-appserv-www-switch-mygallery-php-b-on-line-b-174-b-br-43

 

Tātad lai visi "-----" tiek aizvietoti ar vienu "-", un ja pirmais un pēdējais ir "-", tad tas tiek izdzēsts.

Link to comment
Share on other sites

function fixlink($title) {
$title = strtolower($title);
return preg_replace("/[^a-z0-9-]/", "-", iconv("UTF-8", "ISO-8859-1//TRANSLIT", $title));
}

 

te būs sākuma teksts

<br /> <b>Notice</b>:  Undefined index:  image_title in <b>C:\AppServ\www\switch\mygallery.php</b> on line <b>174</b><br />-43

Link to comment
Share on other sites

Sataisīju.

 

function fixlink($title) {
$title = strtolower($title);
return preg_replace('/\W\W+/', '-', preg_replace("/[^a-z0-9-]/", "-", iconv("UTF-8", "ISO-8859-1//TRANSLIT", $title)));
}

Tātad visi, kas nebūs A-Z, a-z, 0-9 un kuri kopā būs vairāk kā 1, tiks aizvietots ar -.

Link to comment
Share on other sites

function fixlink($title){
$title = strtolower($title);
return preg_replace(array(
	'/[^a-z0-9\-]/',
	'/\-+/',
	'/^-/',
	'/\-$/'
), array(
	'-',
	'-',
	'',
	''
), iconv("UTF-8", "ISO-8859-1//TRANSLIT", $title));
}

1. Visu, kas nav mazie latīņu burti un cipari, aizvietojam ar dash

2. Vienu un vairāk dash'us aizvietojam ar vienu dash

3. Aizvācam dash, kas atrodas stringa sākumā

4. Aizvācam dash, kas atrodas stringa beigās

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...