Strip spaces out

8 posts by 3 authors in: Forums > CMS Builder
Last Post: April 24, 2009   (RSS)

By benedict - January 26, 2009

Hi guys,

I'm using the CMS to populate a line of javascript that would work fine except the code is presenting like this:

<script type="text/javascript">new ToolTip('tooltip-10', 'Learn more about:<br/>
- Expanding businesses into Australia<br/>
- Import and Export<br/>
- International Franchising<br/>
- Migration Law<br/>
- Law Firm Network', { mode: 'cursor', display: 'inline', width: 240, style: 'default', sticky: 0 });</script>

When it needs to present on one line, like this:

<script type="text/javascript">new ToolTip('tooltip-10', 'Learn more about:<br/>- Expanding businesses into Australia<br/>- Import and Export<br/>- International Franchising<br/>- Migration Law<br/>- Law Firm Network', { mode: 'cursor', display: 'inline', width: 240, style: 'default', sticky: 0 });</script>

Can you please let me know how to strip the spaces out so it all appears on one line? This is the code I have currently:

<?php foreach ($servicesRecords as $record): ?>
<div id="tooltip-<?php echo $record['num'] ?>" class="sidenav_heading"><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></div>
<p>
<script type="text/javascript">new ToolTip('tooltip-<?php echo $record['num'] ?>', '<?php echo $record['navigation_bubble'] ?>', { mode: 'cursor', display: 'inline', width: 240, style: 'default', sticky: 0 });</script>
</p>
<?php endforeach; ?>

Thanks.

Re: [benedict] Strip spaces out

By Dave - January 26, 2009

Hi benedict,

Try adding this line:

<?php foreach ($servicesRecords as $record): ?>
<?php $record['navigation_bubble'] = strtr($record['navigation_bubble'], "\n", ""); ?>
...


Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Strip spaces out

By benedict - January 26, 2009

Hi Dave,

Alas, no good. Still does the exact same thing.

Re: [benedict] Strip spaces out

By Dave - January 27, 2009

I'm not sure which spacing characters are present. Try this:

<?php foreach ($servicesRecords as $record): ?>
<?php $record['navigation_bubble'] = preg_replace("/\s+/", " ", $record['navigation_bubble']); ?>
...


If that doesn't work feel free to email me CMS and FTP login details to dave@interactivetools.com and I can take a look for you. (Email, don't post login details to the forum).

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Strip spaces out

By benedict - January 27, 2009

That's done the trick. Thanks Dave.

Re: [gkornbluth] Strip spaces out

By Dave - April 24, 2009

Hi Jerry,

You can "url encode" value with urlencode() such as:
<?php echo urlencode($record['title']); ?> and that will replace ? with %3F etc. See http://ca.php.net/urlencode

You can replace characters with str_replace or preg_replace. See http://ca.php.net/str_replace and http://ca.php.net/preg_replace

Here's some examples:

$str = 'Hello " There * How ? Are You';
$str = preg_replace('/[\"\*\?]/', '', $str);
print $str;


$str = 'Hello " There * How ? Are You';
$replace = array('"','*','?');
$str = str_replace($replace, '', $str);
print $str;


Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Strip spaces out

By gkornbluth - April 24, 2009 - edited: April 24, 2009

Thanks Dave,

I'm sure it will.

I'll give it a look this weekend
The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php