0

I would like to remove white space in a php generated css code, I have different title header which would like to generate through php code.

Titles are like 1) Baby Day Care 2) Baby Night Care

My php codes are like:

<div class="wistia<?php echo $subject->title;?>">

So when I got the class, I got like wistiaBaby Day Care or wistiaBaby Night Care

But I want the class will be look like wistiaBabyDayCare or wistiaBabyNightCare (I want space removed between text).

So how I am going to achieve that?

chris85
  • 23,846
  • 7
  • 34
  • 51
indy
  • 129
  • 1
  • 2
  • 11
  • See http://stackoverflow.com/questions/2109325/how-to-strip-all-spaces-out-of-a-string-in-php – j08691 May 18 '16 at 21:15

2 Answers2

0

That should to the trick:

<div class="wistia<?php echo str_replace(' ', '', $subject->title);?>">

This just uses the str_replace function where you replace the first character with the 2nd character for a given string.

Chief Wiggum
  • 2,784
  • 2
  • 31
  • 44
0

To remove any whitespace simply use preg_replace (regex):

<div class="wistia<?php echo preg_replace('/\s+/', '', $subject->title);?>">
M.M
  • 2,254
  • 1
  • 20
  • 33