You are viewing our Forum Archives. To view or take place in current topics click here.
#11. Posted:
Status: Offline
Joined: Jun 11, 200915Year 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, 200915Year 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.
Since the url is the bit we're having trouble with, that's what you want to encode.
This is where the url is stored, so let's encode it.
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.
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.
- 2useful
- 0not useful
#12. Posted:
Status: Offline
Joined: Jan 16, 201212Year Member
Posts: 20,271
Reputation Power: 17066
Motto: 2b || !2b
Motto: 2b || !2b
Status: Offline
Joined: Jan 16, 201212Year Member
Posts: 20,271
Reputation Power: 17066
Motto: 2b || !2b
speed wrote So let's look at the part that handles the actual embedding.You're a star!
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.
Thank you, this has been doing my head in for ages. Seems simple now.

- 0useful
- 0not useful
#13. Posted:
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,753
Reputation Power: 452
Status: Offline
Joined: Nov 05, 201311Year Member
Posts: 2,753
Reputation Power: 452
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.
I think you can do this with any php code block. Just make sure you have the end statement.
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.
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.