[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Breadcrumb code question

Posted on 2011-05-09
8
Medium Priority
?
319 Views
Last Modified: 2012-05-11
Hi,

I have a breadcrumb that is generated with the code below:

 
if (count($path)) {
			foreach ($path as $link) {
				$output .= $link.'<span class="bcSeparator">'.$params->get('seperator','&raquo;').'</span>';
			}
		}

Open in new window


The problem is ... this will output the following:

Home > Level 1 > Level 2 >

But on the very last node, I don't want the "&raquo;" I want it to look like this:

Home > Level 1 > Level 2

Any ideas?
0
Comment
Question by:Eternal_Student
8 Comments
 
LVL 9

Expert Comment

by:Erdinç Güngör Çorbacı
ID: 35725075
you can use rtrim (http://php.net/manual/en/function.rtrim.php)
or if you want a
$output=preg_replace("/[ >]*$/i","",$output); will also do the trick
if (count($path)) {
			foreach ($path as $link) {
				$output .= $link.'<span class="bcSeparator">'.$params->get('seperator','&raquo;').'</span>';
			}
                        $output = rtrim($output , ">");
		}

Open in new window

0
 
LVL 3

Expert Comment

by:double_helix
ID: 35725402
The easiest way to do this would be to prepend the string you're adding each time...

if (count($path)) {
    foreach ($path as $link) {
        if (strlen($output) > 0) $output .= .'<span class="bcSeparator">'.$params->get('seperator','&raquo;').'</span>';
        $output .= $link;
    }
}

Open in new window



This will add the separator BEFORE each link but only if there is existing content in the output. So your output should look like this:

Home > Level 2 > Level 3

Hope this helps.
0
 
LVL 18

Author Comment

by:Eternal_Student
ID: 35726636
Neither of those seemed to work I got:

Works>Drawings>

&

>Works>Drawings

Respectively.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:meenaxi
ID: 35726638
u can remove the last character also
<?php
if (count($path)) {
			foreach ($path as $link) {
				$output .= $link.'<span class="bcSeparator">'.$params->get('seperator','&raquo;').'</span>';
			}
			$output = substr($output,0,strlen($output)-1);
}
?>

Open in new window

0
 
LVL 18

Author Comment

by:Eternal_Student
ID: 35726704
That doesn't seem to work either?

I am attaching ALL of the PHP for this component.


<?php
	$output = '';
	if ($params->get('home')) {
		$output .= '<span class="bcTitle">'.JText::_('You are here:').'</span>';
		$output .= '<a href="'.JURI::root().'">'.$params->get('home',JText::_('Home')).'</a>';
		if (count($path)) {
			foreach ($path as $link) {
				$output .= '<span class="bcSeparator">'.$params->get('seperator','&gt;').'</span>'.$link;
			}
		}
		if($title){
			$output .= '<span class="bcSeparator">'.$params->get('seperator','&gt;').'</span>'.$title;
		}
	} else {
		if($title){
			$output .= '<span class="bcTitle">'.JText::_('You are here:').'</span>';
		}
if (count($path)) {
			foreach ($path as $link) {
				$output .= $link.'<span class="bcSeparator">'.$params->get('seperator','&gt;').'</span>';
			}
			$output = substr($output,0,strlen($output)-1);
}


	}

	echo $output;
	?>

Open in new window

0
 
LVL 2

Expert Comment

by:meenaxi
ID: 35726745
try by putting the substr statement before echoing output..

$output = substr($output,0,strlen($output)-1);
echo $output;

if it doesnt help u then could u give me the your site URL ?
0
 
LVL 18

Author Comment

by:Eternal_Student
ID: 35726990
No, that didnt work:

http://tinyurl.com/6huvrjo

You can see the breadcrumb in the top left
0
 
LVL 2

Accepted Solution

by:
meenaxi earned 1000 total points
ID: 35727265
try with this
<?php
	$output = '';
	if ($params->get('home')) {
		$output .= '<span class="bcTitle">'.JText::_('You are here:').'</span>';
		$output .= '<a href="'.JURI::root().'">'.$params->get('home',JText::_('Home')).'</a>';
		if (count($path)) {
			foreach ($path as $link) {
				$output .= '<span class="bcSeparator">'.$params->get('seperator','&gt;').'</span>'.$link;
			}
		}
		if($title){
			$output .= '<span class="bcSeparator">'.$params->get('seperator','&gt;').'</span>'.$title;
		}
	}else{
		if($title){
			$output .= '<span class="bcTitle">'.JText::_('You are here:').'</span>';
		}
	
		$i = 0;
		if (count($path)) {
			foreach ($path as $link) {
				$output .= $link;
				if ($i < (count($path)-1))
					$output .='<span class="bcSeparator">'.$params->get('seperator','&gt;').'</span>';
				$i++;
			}
			
		}
	}

	echo $output;
?>

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question