Gossamer Forum
Home : Products : Gossamer Links : PHP Front End :

Category name with +

Quote Reply
Category name with +
Could anyone suggest how to make a $category_short with +-signs between white spaces?
John
Quote Reply
Re: [gotze] Category name with + In reply to
Not sure where/why you would want to do it?

Could be done with a simple global;

Code:
sub { my $tmp = $_[0]; $tmp =~ s/ /+/g; return $tmp; }

You would pass in the URL string with;

Code:
<%global_name($category_short)%>

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Category name with + In reply to
Andy,

The sub you propose looks very much like a perl code. This is posted in the php forum :-)

I want to use the global in category pages. I included search results from Amazon (via web service), and they want white spaces replaced with plus-signs.

John
Quote Reply
Re: [gotze] Category name with + In reply to
Ah, sorry :(

You could try;

<? $var = $category_short; echo preg_replace('\s', '\+', $var); ?>

... in the category.html template (PHP).

Untested, but should work :)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates

Last edited by:

Andy: Aug 18, 2004, 1:24 AM
Quote Reply
Re: [Andy] Category name with + In reply to
Thanks for helping. I've tried this, but can't get it to do anything.
Frown
Quote Reply
Re: [gotze] Category name with + In reply to
Mmm.. been a while since I played with PHP :(

Hows it work now? (using \s and \+)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Category name with + In reply to
This works:

<?php
$string = $category_short;
$pattern[0] = "/ /";
$replacement[2] = "+";
$plustext = preg_replace($pattern, $replacement, $string);
?>

This takes $category_short, e.g., "Gossamer Threads" and creates $plustext, which would be "Gossamer+Threads".
This is for example useful when integrating Amazon web services into your categories.

Thanks Andy, for helping out.

John
Quote Reply
Re: [gotze] Category name with + In reply to
Hi. Not sure what the 3rd line is all about? (its defined as an array, yet you put it in with preg_replace() as a string Crazy).

This should do the trick (little smaller too);

Code:
<?php
$string = $category_short;
$string = preg_replace(' ', '+', $string);
?>

I think the reason my first example of code wasn't working, is because I was using "\s" instead of just " " :(

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Category name with + In reply to
When you use preg_replace you have to have the // for perl compatible regular expressions.

so instead of:

preg_replace("\s", "\+", $string);

It would be:

preg_replace("/\s/", "\+", $string);

However, for a simple replace like that str_replace would be faster:

str_replace("[[:space:]]", "\+", $string);

Hope this helps,

- Jonathan
Quote Reply
Re: [jdgamble] Category name with + In reply to
Ah, I knew it was something like that (I'm used to using a couple of other regex routines, which only need to be quoted). Thanks for clearing that up though :)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates