GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Webmaster Q & Fuckin' A (https://gfy.com/forumdisplay.php?f=27)
-   -   PHP question, I hateeeeeeeee. Easy to do i'm sure... (https://gfy.com/showthread.php?t=1038868)

amateurcanada 09-20-2011 07:43 PM

PHP question, I hateeeeeeeee. Easy to do i'm sure...
 
Hi there! e.g.

$title="i am the best"

i want the output field to be "i-am-the-best" doing a replace of spaces with dashes.

Tell me gods how to do this :D

Babaganoosh 09-20-2011 08:01 PM

http://us.php.net/manual/en/function.str-replace.php

webboy21 09-21-2011 02:14 AM

^what he said....easy to do

idogfy 09-21-2011 05:59 AM

Copy paste that

PHP Code:

<?php
//try it with 
$title='  I  can     replace      several   spaces   ';
//you probably don't want to add a dash at the beginning or at the end of the $title if there is some space at the beginning or at the end
$title trim($title);
// \s+ is the "pattern" you want to replace with dashes
$new_title preg_replace('/\s+/','-',$title);
echo 
$new_title;

Have fun with title and dashes

islandfreaks 09-21-2011 02:24 PM

^ recommended solution :thumbsup

webboy21 09-21-2011 02:36 PM

yup that one is even better....but if he's putting in the string himself he won't be using double spaces etc......and then the first solution is faster I think...but if he doesn't know what the string will look like..the second solution is superior :)


All times are GMT -7. The time now is 04:32 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc