Robert Elsdon Posted July 19, 2009 Share Posted July 19, 2009 Please help me get a code what will replace : ) with <img src="images/smilies/smile.gif"></a> Regards Robert Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/ Share on other sites More sharing options...
Cosizzle Posted July 19, 2009 Share Posted July 19, 2009 you mean echo "<img src='images/smilies/smile.gif'></a>"; Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878230 Share on other sites More sharing options...
Robert Elsdon Posted July 19, 2009 Author Share Posted July 19, 2009 you mean echo "<img src='images/smilies/smile.gif'></a>"; i dont think you got what i ment? i mean like when i type : ) it will automaticly be replaced by <img src="images/smilies/smile.gif"></a> Kind regards Robert Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878232 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 str_replace Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878233 Share on other sites More sharing options...
Robert Elsdon Posted July 19, 2009 Author Share Posted July 19, 2009 str_replace could you give an example of it? if newish to php and dont no str replace atm thanks Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878235 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 follow the link. It shows the syntax for it, as well as examples, followed by a ton of user contributed notes about it. Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878239 Share on other sites More sharing options...
Robert Elsdon Posted July 19, 2009 Author Share Posted July 19, 2009 easy enought for you to say that im a n00b to php please just make me one its easy for you ill learn easier if helped Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878249 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 I don't understand how you think me posting an example will be any easier for you to understand than the example(s) in the link I posted. It sounds like you don't an example, but actual code relevant to your problem at hand. Well we aren't here to write your code for you. Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878264 Share on other sites More sharing options...
Robert Elsdon Posted July 20, 2009 Author Share Posted July 20, 2009 Im looking for a little help? <?php $string = "This is be a test"; echo str_replace(" is", " could", $string); ?> where it says could how would i make a image show there? Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878929 Share on other sites More sharing options...
.josh Posted July 20, 2009 Share Posted July 20, 2009 by replacing "could" with the image tag... echo str_replace(" is", "<img src='...' ... />", $string); that will replace " is" with "<img src='...' ... />" (no outer double quotes) Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878932 Share on other sites More sharing options...
Robert Elsdon Posted July 20, 2009 Author Share Posted July 20, 2009 thanks, i had a rough idea lol i was using double quotes thank alot mate i actually learned hehe Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878934 Share on other sites More sharing options...
Robert Elsdon Posted July 20, 2009 Author Share Posted July 20, 2009 Now, heres my index page (home page of site). <?PHP session_start();?> <? include("includes/connect.php"); ?> <html> <head> <title> Local Host </title> <link href="includes/style.css" rel="stylesheet" type="text/css"> </head> <div align="center"> <body> <div class="nc_wrapper"> <? include ('includes/header.php'); ?> <div class="spacer"></div> <? include ('includes/left-menu.php'); ?> <div class="content"> <table cellspacing="1" cellpadding="0" border="0" style="width:100%; background:#000000"> <tr><td class="content_head"> Content </td></tr> <tr><td class="actual_content"> Welcome to localhost, This is just a temperary website as for now untill i get it 100% complete! THEN i am giving it to a good friend of mine who owns - <a href="http://pulse-box.com" target="new_window">Pulse-Box</a> so he can sell it to any of yous who like it. :) :) </td></tr> <tr><td class="content_foot"></td></tr> </table> </div> </div> <? include ('includes/footer.php') ?> </div> </body> </html> How would i make it change the in the content with a image by using this script? <?php $string = "This is a test "; echo str_replace(" ", " <img src='images/smilies/smile.gif'/>", $string); ?> Regards Robert Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878941 Share on other sites More sharing options...
.josh Posted July 20, 2009 Share Posted July 20, 2009 You can't do it like that. Once the content is output, you can't go back and change it. At least, not with php. I suppose you could use some client-side scripting to do it, but I don't think that's what you're really looking to do. I have to ask...if you have a page hardcoded like that, why not just put the image tags in there in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878947 Share on other sites More sharing options...
Robert Elsdon Posted July 20, 2009 Author Share Posted July 20, 2009 its for a shoutbox, When you type : ) it replaces with mage automaticly Regards Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878953 Share on other sites More sharing options...
.josh Posted July 20, 2009 Share Posted July 20, 2009 I'm not seeing anything for that in the code you posted. I just assumed that you were wanting to replace that line of : ) with images in that td tag. Perhaps it is in one of your includes? Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-878960 Share on other sites More sharing options...
Robert Elsdon Posted July 20, 2009 Author Share Posted July 20, 2009 Yeah it is the shoutbox is in left-nav.php include Is there a script i can add to the shoutbox to replace with image smilie? Thanks, Robert Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-879010 Share on other sites More sharing options...
.josh Posted July 20, 2009 Share Posted July 20, 2009 okay so if left-nav.php is what displays the shoutbox entries, you're going to have to integrate the str_replace in that bit of code. Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-879018 Share on other sites More sharing options...
Robert Elsdon Posted July 20, 2009 Author Share Posted July 20, 2009 How would i do multiple tags ? heres an example but it doesnt work? You might get what i mean.. <?php $string = "This is a test "; echo str_replace(" ", " <img src='images/smilies/smile.gif'/>", $string); echo str_replace(" ", " <img src='images/smilies/sad.gif'/>", $string); echo str_replace(" ", " <img src='images/smilies/grin.gif'/>", $string); echo str_replace(" ", " <img src='images/smilies/tounge.gif'/>", $string); ?> The last 3 echo str_replace are examples Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-879022 Share on other sites More sharing options...
.josh Posted July 20, 2009 Share Posted July 20, 2009 dude you're making this harder than it needs to be. Where in left-nav.php is the part that displays the shouts? Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-879027 Share on other sites More sharing options...
Robert Elsdon Posted July 20, 2009 Author Share Posted July 20, 2009 The form to post messages onto the shoutbox <form action="<? echo $php_self ?>#bottom" method="post"> <center> <? mysql_connect("localhost","root","12345678"); mysql_select_db("shoutbox"); if($_POST['submit']) { ?> <? $name = $_POST['name']; $message= $_POST['message']; $time=date("h:ia d/m/y"); if(!$message) { ?> Please enter a message. <? } else if($message == 'Enter Message') { ?> <font color="#b2eb62"> PLEASE ENTER A MESSAGE</font> <? } else { ?> <? $insertshout="INSERT INTO shoutbox(name,message,time) VALUES ('$name', '$message','$time')"; mysql_query($insertshout) or die("Cannot insert shout"); ?> <script type="text/JavaScript">window.location='index.php';</script> <? } ?> <? } else { } ?> <table> <? if($_SESSION['logged_in'] == 'Yes') { ?> <tr><td> <center>Username :</center> <center><input class="text_input" type='text' value='<?=(ucwords($_SESSION[user_name]));?>' name='name' size=30 maxlength='100' readonly="yes"></center> </td><tr> <? } else { ?> <? } ?> <tr><td> <center>Message :</center> <center><input class="text_input" type="text" maxlength="300" name="message" id="message" value="Enter Message" onclick=document.getElementById('message').value=""; onBlur="shoutmessage();"></center> </td></tr> <tr><td> <center><input class="button" type="submit" name="submit" value="Post Shout" style="margin:0px;"></center> </td></tr> </table> </form> And heres the shoutbox itself which displays the posts <?PHP session_start(); ?> <? include("includes/connect.php"); // Get the messages from the databse $get_messages = mysql_query("select * from shoutbox"); $amountofmessages = mysql_num_rows($get_messages); $select_shouts = mysql_query("select * from shoutbox ORDER BY id DESC LIMIT 10"); ?> <table cellpadding="0" cellspacing="0" border="0" style="width: 100%;"> <? $color='dark'; while($r=mysql_fetch_array($select_shouts)) { if($color == 'dark') { ?> <tr class="dark"> <td><?=$r["time"];?></td> <td><?=$r["date"];?></td> <td><b><font color="#b2eb62"><?=$r["id"];?></font></b> </td> </tr> <tr> <td colspan="3" align="left" style="padding:3px;"> <b><?=$r["name"];?></b><b><font color="#b2eb62"> -</b> </font><?=$r['message'];?> </td> </tr> <? $color='light';} else { ?> <tr class="dark"> <td><?=$r["time"];?></td> <td><?=$r["date"];?></td> <td><b><font color="#b2eb62"><?=$r["id"];?></font></b> </td> </tr> <tr> <td colspan="3" align="left" style="padding:3px;"> <b><?=$r["name"];?></b><b><font color="#b2eb62"> -</b> </font><?=$r['message'];?> </td> </tr> <? $color='dark';} } ?> </table> <? if(!$_SESSION['logged_in'] == 'Yes') { ?> <p align="center"> <font color="#b2eb62">you need to be logged in to view this form to post on shoutbox! </ br> Please, <a href="index.php">Login</a> <b>/</b> <a href="register.php">Register</a> to post a message! </p></font> <? } ?> Regards, Robert Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-879031 Share on other sites More sharing options...
.josh Posted July 20, 2009 Share Posted July 20, 2009 Okay, in the shoutbox code that displays the actual shouts, you have these 2 lines: while($r=mysql_fetch_array($select_shouts)) { if($color == 'dark') { ?> change that to while($r=mysql_fetch_array($select_shouts)) { $r['message'] = str_replace("", "<img src='images/smilies/smile.gif'/>", $r['message']); if($color == 'dark') { ?> Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-879058 Share on other sites More sharing options...
Robert Elsdon Posted July 20, 2009 Author Share Posted July 20, 2009 OMG You are a genius!! Thank you so so much mate! Quote Link to comment https://forums.phpfreaks.com/topic/166536-solved-php-script-to-replace-with/#findComment-879069 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.