Jump to content

replace text with an image?? help please :x


richiec

Recommended Posts

use str_replace

 

<?php
$str = 'Sample [image_here] text';         // result of file_get_contents

echo str_replace ('[image_here]', '<img src="myimage.gif">', $str);


/**
* multiple images sample
*/

$s = array (
          '[image1]',
          '[image2]',
          '[image3]'
        );
$r = array (
          '<img src="imagex.gif">',
          '<img src="imagey.gif">',
          '<img src="imagez.gif">'
        );

$str = 'Sample [image1] text [image2] with more [image3] images';         // result of file_get_contents

echo str_replace ($s, $r, $str);

?>

if you go here http://dksgfx.freehostia.com/FW/parsetest/profileparse.php

 

put in DevilKnightSparda that will bring up the list of skills that i currently have cast on my account inside the table. Above the table is the skill images. i want to replace the text found from file_get_contents which pulls the text inside the table with the images.

 

 

ok... let me try again..

 

this part gets the information about which skills are cast on the profile you search for...

 

$url = 'http://sigil.outwar.com/profile.php?transnick=';
if (isset($_POST['submit'])){
if (empty($_POST['cid'])){
$cid = ''; }
else {
$cid = '' . $_POST['cid'];
}
$file = file_get_contents($url . $cid);
list($before, $after) = split("/images/skill_13.gif", $file);
list($looting) = split("You steal", $after);

list($before, $after) = split("/images/skill_46.gif", $file);
list($wall) = split("Casting shield", $after);

list($before, $after) = split("/images/skill_4.gif", $file);
list($stealth) = split("Increases targets HP", $after);

list($before, $after) = split("/images/skill_28.gif", $file);
list($fort) = split("You receive +", $after);

list($before, $after) = split("/images/skill_15.gif", $file);
list($cop) = split("Reduces your damage taken", $after);

list($before, $after) = split("/images/skill_7.gif", $file);
list($bag) = split("Makes all your supplies invulnerable", $after);

list($before, $after) = split("/images/skill_50.gif", $file);
list($bfa) = split("You receive +", $after);

list($before, $after) = split("/images/skill_3.gif", $file);
list($emp) = split("Increases targets ATK", $after);

list($before, $after) = split("/images/skill_9.gif", $file);
list($lust) = split("Target receives +", $after);

list($before, $after) = split("/images/skill_2952.gif", $file);
list($no problem) = split("Reward buff for", $after);

 

this part displays what skills it finds

 

echo "<table border=\"1\">
<tr>
    <td width=\"188\"><b>$cid</b></td>
    <td width=\"1000\">$looting $wall $stealth $fort $cop $bag $bfa $emp $lust $no problem</td>

  </tr>
  
  ";

 

what i want to do is replace where on the site it has:

 

" hspace="2" width="25" height="25" ONMOUSEOVER="popup(event,'

 

with the correct image of that skill

str_replace() is what you're looking to use here.

 

http://www.php.net/str_replace

 

That documents how to use it.

 

Something like this I imagine:

str_replace('" hspace="2" width="25" height="25" ONMOUSEOVER="popup(event,\'',$image,$data);

 

Where:

$image contains the link to the image

$data hold the string containing the string you want to replace

ok i did what you said but i still cant get it to work.. in adidtion to the code i showed before this is what i also have now..

 

$lootingimage = "http://sigil.outwar.com/images/skill_13.gif";

$data = 'hspace="2" width="25" height="25" ONMOUSEOVER="popup(event,'

 

Then i have the example of what you told me..

 

str_replace('hspace="2" width="25" height="25" ONMOUSEOVER="popup(event,\'',$lootingimage,$data);

 

and it gives me the following error...

 

"Parse error: parse error, unexpected T_VARIABLE in /home/www/dksgfx.freehostia.com/FW/parsetest/profileparse.php on line 32"

 

line 32 is

 

$data = 'hspace="2" width="25" height="25" ONMOUSEOVER="popup(event,'

 

any idea what im doing wrong :-s

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.