Jump to content


Replacing Text Help


5 replies to this topic

#1 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 22 January 2006 - 07:51 PM

Hey, I'm a staff member of good ol' Tutorialfx, and I've got a dilema with using a php script.

I'm trying to run a php script to replace certain text with an HTML element.

I think I have the script done correctly, here is an example.

<?php

$tooltip = "<a class="tutfx" onMouseover="ddrivetip('<div id=tutfx_tiptitle>Title</div><<hr width=100% height=1 /><img id=tutfx_tipimg src=tools/brush_tool.gif />Description','#E9ECF0','300')";
onMouseout="hideddrivetip()">Tutfx</a>";
  $content = "Tutfx"
  $content = eregi_replace("Tutfx", $tooltip, $content);

?>

So in this example, I'm trying to replace any text of 'Tutfx' with this tooltip HTML code.

I've already got the JavaScript that the HTML is dependant on.
But first of all, I would like to know if this code is correct.
And second of all, I would like to know how to use it, in other words, how do I tell the HTML document to use this script?


I've searched tutorials and resources and such, but seemingly I must be dumb lol. None of it makes sense to me.

Thanks in advanced to anyone who could help me hopefully.

It would be of great help if someone could kindly guide me through this on messanger.
Heres my contact info (even though it's already in my profile).

AIM: Demonslay335
MSN: Michael_Todd_335@yahoo.com
Yahoo: Michael_Todd_335@yahoo.com

#2 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 22 January 2006 - 08:48 PM

eregi_replace would not be the best choice for this problem. What I would recommend doing is using str_replace. ( http://us2.php.net/str_replace )

Secondly, your code is not correct and when ran, will probably give you a error similar to "Parse error: parse error, unexpected T_STRING". That is because you are mixing double quotes with double quotes without nullin them.

The correct php code will be
<?php

$tooltip = '<a href="#" class="tutfx" onmouseover="ddrivetip(\'<div id=tutfx_tiptitle>Title</div><<hr width=100% height=1 /><img id=tutfx_tipimg src=tools/brush_tool.gif />Description\',\'#E9ECF0\',\'300\')" onmouseout="hideddrivetip()">Tutfx</a>';
$content = 'Tutfx';
$content = str_replace("Tutfx", $tooltip, $content);
echo $content;
?>

With that and I am guessing your using a script from dynamic drive, it should work. Just make sure that the part with dynamic drive is correct and you should be good to go!

Edited by Chaos King, 22 January 2006 - 08:50 PM.


#3 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 22 January 2006 - 11:48 PM

Well, I tried that, to no avail.
I checked it and it looks valid and all...

In my HTML document I just added it with the <script> tag, making an external script for this. I've tried putting it in the head and the body section, neither works. I would believe it belongs in the head?

Here is my attempt at it:
www.tutorialfx.com/demonslay/test_page.html

Also in that directory is the php file.
www.tutorialfx.com/demonslay/tutfx.php

I haven't done anything to the script you gave me to alter it, so I have no idea what is wrong. :P

Also I have no idea what a dynamic drive is... but it's uploaded to Tutorialfx, which I know has whatever it is to let php run...

#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 23 January 2006 - 10:41 AM

Isn't Ghost the admin over at tutorialfx? I believe he knows quite a bit about php and could help you a bit.
But either way, php doesn't go with the <script> tag. Heres an example of how you add php to html:
<html>
<head>
<title>Blah</title>
</head>

<body>
This is just a bunch of fill text... it's optional...<br>
<?
// All of you're php code here
echo 'Foo<br>';
?>
More filler text... doesn't matter if it's here or not...
</body>
</html>


#5 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 23 January 2006 - 04:39 PM

Ya, Ghost is admin, but he's on vacation...

I wanna get this set up for him to add right when he gets back lol.


Erm, ok, I've tried that, and I still get no results. :)
Do I have to save it as .php or something?

Also is there a way to make it refer to it as an external script? Because once I can get this set up, it will very long, as I'm doing this for every Photoshop tool, and many common shortcuts... going to be long script lol.

But ya, I still can't get this to work. :(

#6 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 23 January 2006 - 06:59 PM

Yes... it has to be saved as .php...
But for it to be an external script, simply take where you would've put it in the html, and instead of putting the whole script in that spot, put
<? include('file.php'); ?>
Where file.php is the file you want to run.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users