You are viewing our Forum Archives. To view or take place in current topics click here.
#11. Posted:
speed
  • Winter 2018
Status: Offline
Joined: Jun 11, 200914Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200914Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
So let's look at the part that handles the actual embedding.

echo '<li><img class="img" src="ss/' . $dirArray[$index] . '" alt="Image" /><span>' . $dirArray[$index] . '</span>';


Since the url is the bit we're having trouble with, that's what you want to encode.

$dirArray[$index]


This is where the url is stored, so let's encode it.


$unencoded_url = $dirArray[$index];
$encoded_url = rawurlencode($unencoded_url);
echo '<li><img class="img" src="ss/' . $encoded_url . '" alt="Image" /><span>' . $encoded_url . '</span>';


You'll pass the variable holding the unencoded url into the rawurlencode function, which returns the encoded url. You then use that as the source for the image.
#12. Posted:
Craig
  • Winter 2022
Status: Offline
Joined: Jan 16, 201212Year Member
Posts: 20,271
Reputation Power: 17065
Motto: 2b || !2b
Motto: 2b || !2b
Status: Offline
Joined: Jan 16, 201212Year Member
Posts: 20,271
Reputation Power: 17065
Motto: 2b || !2b
speed wrote So let's look at the part that handles the actual embedding.

echo '<li><img class="img" src="ss/' . $dirArray[$index] . '" alt="Image" /><span>' . $dirArray[$index] . '</span>';


Since the url is the bit we're having trouble with, that's what you want to encode.

$dirArray[$index]


This is where the url is stored, so let's encode it.


$unencoded_url = $dirArray[$index];
$encoded_url = rawurlencode($unencoded_url);
echo '<li><img class="img" src="ss/' . $encoded_url . '" alt="Image" /><span>' . $encoded_url . '</span>';


You'll pass the variable holding the unencoded url into the rawurlencode function, which returns the encoded url. You then use that as the source for the image.
You're a star!

Thank you, this has been doing my head in for ages. Seems simple now.
#13. Posted:
CriticaI
  • Shoutbox Hero
Status: Offline
Joined: Nov 05, 201310Year Member
Posts: 2,737
Reputation Power: 448
Status: Offline
Joined: Nov 05, 201310Year Member
Posts: 2,737
Reputation Power: 448
I know your question has already been answered. But you should consider writing your for loops and if statements differently if you plan on integrating html.

It will make it a lot easier to read and manage your html. Here is some example code you can test if you want.



<style>
  .thing {padding: 1rem; margin: 1rem;}
  .yellow {background: #fff000;}
  .grey {background: #eee;}
</style>


<?php for($i = 0; $i < 5; $i++): ?>
  <div class="thing <?php echo ($i % 2 ) ? 'grey' : 'yellow'?> ">
    <h3> <?php echo $i ?> </h3>
  </div>
<?php endfor ?>



I think you can do this with any php code block. Just make sure you have the end statement.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.