Format output to lowercase - php

I need to change the output of <?php echo $EM_Category->name; ?> to lowercase only.
Output now is Entertainment. How would I get it to entertainment
Full section of code is:
<?php foreach(EM_Categories::get(array('orderby'=>'category_name')) as $EM_Category): ?>
<a href="<?php echo THEME_URL; ?>/events/category/<?php echo $EM_Category->name; ?>" class="browse-cat">
<span><?php echo $EM_Category->name; ?></span><img src="<?php echo THEME_URL; ?>/images/box_arrow.png" alt="arrow" height="15" width="15">
</a>
<?php endforeach; ?>

That would be the strtolower function.
<?php echo strtolower($EM_Category->name); ?>

<?php echo strtolower($EM_Category->name); ?>
http://us.php.net/strtolower

<?php echo strtolower($EM_Category->name); ?>

In PHP you use:
echo strtolower($EM_Category->name);

Related

Dont show if field is left blank

This is the code that shows a Manufacturer Part Number on my product listing
<span class="p-rewards">MPN:<?php echo $text_mpn; ?></span> <?php echo $mpn; ?><br />
what I would like to do is not show the MPN: Field on the product page if the $text_mpn field is blank, e.g if no part number is listed.
You can put an if statement around it. You can close the PHP code block after the if, put your code inbetween and open a new PHP code block to close it:
<?php if ($text_mpn != ''){ ?>
<span class="p-rewards">MPN:<?php echo $text_mpn; ?></span> <?php echo $mpn; ?><br />
<?php };>
For blocks like this, it can be a bit messy and unclear to see where the block ends if you use normal curly braces, so you might consider the Alternative syntax for control structures for these cases:
<?php if ($text_mpn != ''):?>
<span class="p-rewards">MPN:<?php echo $text_mpn; ?></span> <?php echo $mpn; ?><br />
<?php endif;>
try this:
<?php if($mpn != ""){ ?>
<span class="p-rewards">MPN:<?php echo $text_mpn; ?></span> <?php echo $mpn; ?><br />
<?php } ?>
try this
<?php if(strlen($text_mpn) > 0) echo "<span class='p-rewards'>MPN:".$text_mpn."</span>".$mpn."</br>"; ?>
Case 1:
You can use empty() for check is variable is empty or not.
<?php if(empty($mpn)){ ?>
<span class="p-rewards">MPN:<?php echo $text_mpn; ?></span> <?php echo $mpn; ?><br />
<?php } ?>
Case :2
You can simply use display:none if you wants to hide control.you can simply add attribute of style.
<div <?php if(empty($mpn))
{ echo 'style="display:none"';}
else {echo 'style="display:block"';}
?> >
<span class="p-rewards">MPN:<?php echo $text_mpn; ?></span> <?php echo $mpn; ?><br />
</div>
<?php
$mpn = 'Ram Pukar';
$text_mpn = 'Hello ';
echo $text = !empty($mpn) ? '<span class="p-rewards">MPN: '.$text_mpn.'</span>'.$mpn.'<br />':null;
?>
Output:
MPN: Hello Ram Pukar

How to convert input text to image?

I've created a rating star system that allows user to rate 1-5.
How do I change the numbers 1-5 to stars?
These are the codes below that show the numbers for the user to rate.
<?php foreach(range(1,5)as $rating):?>
<a href="rate.php?article= <?php echo $article->id; ?> &rating= <?php echo $rating ; ?> ">
<?php echo $rating; ?> </a>
<?php endforeach;?>
Are there any ways I can convert them to an image or do I have to redo my code?
Yeah for sure.
<?php foreach(range(1,5)as $rating):?>
<a href="rate.php?article= <?php echo $article->id; ?> &rating= <?php echo $rating ; ?> ">
<?php echo '<img src="images/rating_'.$rating.'.png">'; ?> </a>
<?php endforeach;?>
Now simply create the folder images and insert rating_1.png, rating_2.png and so on.
BTW: Maybe it is easier and better for you when you use it in this way (only to show):
<?php
$bla = $article->id;
foreach(range(1,5)as $rating){
echo('
<a href="rate.php?article='.$bla.'&rating='.$rating.'">
<img src="images/rating_'.$rating.'.png">
</a>
');
}
?>

substr not working with $item->getTitle

I'm making a website with Joomla and am using RokSprocket to display some news. Now, some Titles are too long, so I wanted to shorten it after a certain character number, but it's not working. Am a total php noob, my apologies.
Here's the whole code:
<li data-lists-item>
<h4 class="sprocket-lists-title ">
<?php if ($item->custom_can_have_link): ?><a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>"><?php endif; ?>
<?php if(strlen($item->getTitle)>10)
echo substr($item->getTitle,0,10) . ' ...';
else
echo $item->getTitle();?></a>
<div class="date"><?php echo date('d.M. Y', strtotime($item->getDate()));?></div>
</h4>
<span class="sprocket-lists-item" data-lists-content>
<span class="sprocket-padding">
<?php if ($item->getPrimaryImage()) :?>
<img src="<?php echo $item->getPrimaryImage()->getSource(); ?>" class="sprocket-lists-image" />
<?php endif; ?>
<?php echo $item->getText(); ?>
<?php if ($item->getPrimaryLink()) : ?>
<span><?php rc_e('READ_MORE'); ?></span>
<?php endif; ?>
</span>
</span>
</li>
I'm hoping it's something very obvious and I'm just being stupid. Thanks a bunch already!
$item->getTitle is probably a method not a property, so try:
$item->getTitle(); // <-- parenthesis
Change to:
<?php if(strlen($item->getTitle())>10)
echo substr($item->getTitle(),0,10) . ' ...';

Limiting a foreach loop to the first array

here is my code:
<?php
foreach ($productsRecord['images'] as $upload):?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['urlPath'] ?>" alt="" /><br />
<?php endif ?>
<?php endforeach ?>
How would I go about limiting the results to only the first result, would I use a break; statement?
Cheers
Try to use current()
your code shall like that:
<?php reset($productsRecord['images']); ?>
<?php $upload = current($productsRecord['images']);?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['urlPath'] ?>" alt="" /><br />
<?php endif ?>
To more information about the current() check the manual:
http://php.net/manual/en/function.current.php
Just use the first element of the array directly
$productsRecord['images'][0]
No need to loop here.
Yes, use break
<?php break; endforeach; ?>

Output image src with SimpleXML

I'm trying to output an image with SimpleXML, but the image tag doesn't appear in the source code.
Can anyone help me outpout this image:
Here's my XML and code:
<?php foreach($xml->Event as $event) { ?>
<li>
<a href="<?php echo $event->link; ?>">
<?php if ($event->Media['url'] == !null) { ?>
<img src="<?php echo $event->Media['url'];?>" alt="<?php echo $event->title;?> thumbnail" />
<?php } ?>
<h3><?php echo $event->title; ?></h3>
<p><strong><?php echo $event->beginDate; ?> at <?php echo $event->beginTime; ?></strong></p>
<p><?php echo $event->location; ?></p>
</a>
</li>
<?php } ?>
Your issue is here:
<?php if ($event->Media['url'] == !null) { ?>
<img src="<?php echo $event->Media['url'];?>" alt="<?php echo $event->title;?> thumbnail" />
<?php } ?>
You're trying to access url as though it were an attribute, you need to access it as a child element by using ->url instead.
<?php if ($event->Media->url != null) { ?>
<img src="<?php echo $event->Media->url;?>" alt="<?php echo $event->title;?> thumbnail" />
<?php } ?>
EDIT: By the way, == !null works as you expect, but != null is a bit friendlier and less confusing
Your if statement is incorrect. It should be:
if ($event->Media['url'] != null)

Categories