hyphen
5 posts by 2 authors in: Forums > CMS Builder
Last Post: July 6, 2011 (RSS)
By Toledoh - July 5, 2011
I'm trying to add the following code;
workshopsDetail.php?title=$group
And this generates:
workshopsDetail.php?title=getting started, but I need it to show the hypens... workshopsDetail.php?title=getting-started
any ideas?
Tim (toledoh.com.au)
Re: [Toledoh] hyphen
By Dave - July 5, 2011
Are you sure you don't want it urlencoded? Such as:
workshopsDetail.php?title=<?php echo urlencode($group); ?>
Or:
<?php echo "workshopsDetail.php?title=" .urlencode($group); ?>
Let me know if that works, or if you really do want hyphens.
Hope that helps!
interactivetools.com
Re: [Dave] hyphen
By Toledoh - July 5, 2011
The complete bit of code is actually
<?php
$old_group = ''; // init blank var.
foreach ($eventsRecords as $record):
$group = $record['workshop:label']; // load sub-group value from record.
if ($group != $old_group) { // If different from the last sub-group value, print the sub-group name.
echo "<a href='$group'><h2>$group</h2></a>";
}?>
How do I use urlencode there?Tim (toledoh.com.au)
Re: [Toledoh] hyphen
By Toledoh - July 5, 2011
<?php
$old_group = ''; // init blank var.
foreach ($eventsRecords as $record):
$groupnum = $record['workshop']; // load sub-group value from record.
$group = $record['workshop:label']; // load sub-group value from record.
if ($group != $old_group) { // If different from the last sub-group value, print the sub-group name.
echo "<a href='workshopsDetail.php?title=".urlencode($groupnum)."'><h2>$group</h2></a>";
}?>
Thanks!
Tim (toledoh.com.au)
Re: [Toledoh] hyphen
By Dave - July 6, 2011
I noticed the "if different from the last... print" code. Check out these two functions I use from time to time. You may find them helpful in future:
//
function sameAsLastValue($value) {
static $lastValue;
if ($value == $lastValue) { return true; }
$lastValue = $value;
return false;
}
//
function alreadySeen($value) {
static $seenList = array();
// check if alreadyu seen
if (@$seenList[$value]) { return true; }
// mark as seen
$seenList[$value] = true;
return false;
}
You use them like this:
$names = array('Dave', 'Dave', 'Tim', 'Dave');
// prints "Dave, Tim, Dave"
foreach ($names as $name) {
if (sameAsLastValue($name)) { continue; }
print "$name, ";
}
print "<hr/>";
// prints "Dave, Tim"
foreach ($names as $name) {
if (alreadySeen($name)) { continue; }
print "$name, ";
}
Hope that helps!
interactivetools.com