Jump to content

Recommended Posts

hello all, i don't know if this sould be in here or the mysql help. But i am currently using a string replace script to change words in to faces ie :

 

$words = array('', ':-)', ':^)');
$faces = array('<img src=images\emoticons\smile.gif />',);
$message['msg'] = str_replace($words, $faces, $message['msg']);

 

That works fine, i was just woundering is there a way to do this via database, so every time i wanna add a new face etc... i dont have to keep editing the page?

Link to comment
https://forums.phpfreaks.com/topic/84850-hiya-image-replace/
Share on other sites

I think it should possible.

 

Have a table that stores all the words. Have another table with all the image loactions. Link the image to the words via the primary and forgine keys,

 

Then all you need to do is query the database on the user input ~ :). Then if the result == 1 then find out the image id and query the picture table so the scr and echo it out.

Link to comment
https://forums.phpfreaks.com/topic/84850-hiya-image-replace/#findComment-432559
Share on other sites

Yeah you can use one, better practice to have two, normalisation an all. It depends on how big the database will get. Also some words for a smailey face may be

 

:)

:-)

:>)

 

Therefore there could be hundreds of instances of the same image source. To change them may be a pain in the arse. At least with two tables he only has to change one item.

Link to comment
https://forums.phpfreaks.com/topic/84850-hiya-image-replace/#findComment-432563
Share on other sites

atm the only script it is used on is a update script the message is in the db ie : message : hiya :) then when its pulled out the db it goes throught the string replace and comes out as : Hiya  :). but every time i add a new one dont wanna edit the file so tohught might be easier to keep them in the db

Link to comment
https://forums.phpfreaks.com/topic/84850-hiya-image-replace/#findComment-432567
Share on other sites

ok so when you pull hiya ":)" out of your database you need to split the string up, One into text and the other into the image. Once you have done that you can query the databse with you new variable. Then the result return can be set to a variable as well. Then set your img source to the query result variable.

 

This is very dependent on your image being in the same location every time. Use this php function to seperate the words

 

http://uk3.php.net/manual/en/function.explode.php

Link to comment
https://forums.phpfreaks.com/topic/84850-hiya-image-replace/#findComment-432578
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.