Furry stuff, oekaki stuff, and other stuff.
You are not logged in.
Well, I'm working on another site right now and I was wondering how one would be able to do something like
<table>
<tr>
<td>
[image:1]
</td>
</tr>
</table>
on their profile.. which would convert to something like
<table>
<tr>
<td>
<img src="http://www.site.com/kemono.gif">
</td>
</tr>
</table>
which is similar to what deviantart uses for their [user:name] XD
I'm wondering in my head if it has anything to do with str_replace, though I've only recently used that for my watch/friends/message center list for OA XD
Thanks for the help! :3
Offline
It's easy to do something like this:
[ img:http://www.site.com/kemono.gif]
to
<img src="http://www.site.com/kemono.gif" />
Although you can never be quite sure what you're getting yourself into since images are being fetched from other servers.
If you're looking to grab specific information stored in the database and inserting it into the profile, you'll have to be more specific what you're getting. "kemono.gif" doesn't tell me much.
Offline
Ah, to be more specific: I fetch 3 names from the picture database that I want to specify as [image:1] [image:2] [image:3] etc
[image:1] --> $image1 = 158gsa.png [image:2] --> $image2 = 5849ds.png [image:3] --> $image3 = 38s9dfd.png
so when a user wants to customize his or her page, they can do something like
<style type="text/css"> <!-- .image { border-style: dashed; border-color: gray; border-width: 1px; } --> </style> <img src="[image:1]" hspace=5 vspace=5 class="image">
where in PHP, [image:1] will be read as:
<img src="<?=$image1;?>" hspace=5 vspace=5 class="image">
I think it has something to do with str_replace:
// this won't really work, just to show the value of usercode $usercode = "<img src="[image:1]" hspace=5 vspace=5 class="image">"; // not sure if this will really work, beginning of the variable $subj = '<?='; // adding the value $subj .= '$image1'; // not sure if this will really work either! ends the variable. $subj .= ';?>'; // replacing [image:1] with <?=$image1;?> $str = str_replace("[image:1]", $subj, $usercode);
Which would return [image:1] as <?=$image1;?>.. but I'm not sure if it can work this way at all XD
Would this be the right way to go? Or is there some other way to do something like that?
Thank you!
Offline
For the most part, this is pretty simple text replacement. However, you need to insert the actual image names into the output. You can't use <?=$image1?>, as it will be printed literally.
What technique we use depends how the image names are being fetched. How are you getting names from the database, and under what sorting condition? Are the images from a field (such as uploaded images), or are you getting the newest three images, archived images, etc? Will the image names be contained in a keyed array or a regular array? The regular array would be easier, but requires a loop with mysql_result() instead of mysql_fetch_array().
Offline