Question: Hi I am echoing out a field name which is going to be part of a url. However the name itself has uppercase lettyers in it so I have made them all lower on the echo. There is however a space between words. Is there a way I can also replace any spaces here with a hiphen on the echo?

```
<?php echo strtolower($row["myfield"]); ?>

```

Answer: 
You can simply replace the spaces with another string:

```
<?php echo str_replace(' ', '-', strtolower($row["myfield"])); ?>

```

> 
> mixed str\_replace ( mixed $search , mixed $replace , mixed $subject [,
>  int &$count ] )
> 
> 
> 

Documentation:
<https://secure.php.net/manual/en/function.str-replace.php>
For just spaces, use str\_replace:

```
   <?php echo str_replace(' ', '',strtolower($row["myfield"])); ?>

```

For all whitespace, use preg\_replace:

```
  <?php echo  preg_replace('/\s+/', '', strtolower($row["myfield"])); ?>

```