Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Anyone familiar with str_replace(); ?
Old 06-10-2005, 06:34 PM Anyone familiar with str_replace(); ?
Karl89.co.uk's Avatar
Novice Talker

Posts: 7
Trades: 2
I am making a news script for my website, and on the add comments bit I am adding smilieys. I have never used str_replace(); before and I need a little bit of help.

Here is the code for the actual replacements of the into :

PHP Code:
$comments str_replace(":)","<img src=\"images/icons/smile.jpg\">,$comments");
$comments.= str_replace(":(","<img src=\"images/icons/sad.jpg\">,$comments");
$comments.= str_replace(":|","<img src=\"images/icons/blank.jpg\">,$comments");
$comments str_replace(":d","<img src=\"images/icons/grin.jpg\">,$comments");
$comments str_replace(":'(","<img src=\"images/icons/cry.jpg\">,$comments");
$comments str_replace(":p","<img src=\"images/icons/tounge.jpg\">,$comments");
$comments str_replace(";)","<img src=\"images/icons/wink.jpg\">,$comments"); 
When I go to add my comments I get this error:

Warning: Wrong parameter count for str_replace() in /home/karl89/public_html/modules/home/added.php on line 11

For each of the str_replace(); functions...

Can anybody help me out? It would be much appreciated.

Thanks,
Karl
Karl89.co.uk is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-10-2005, 06:38 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
PHP Code:
 $comments str_replace(":)""<img src=\"images/icons/smile.jpg\">"$comments); 
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 06-11-2005, 02:50 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Use preg_replace() in this case as it allows to pass array of matches and array of replacements in one call not to call str_replace() on every smile.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 06-11-2005, 08:29 AM
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Heres one i made earlier:

PHP Code:
<?
function smilies($content) {

        
$content str_replace(":)""<IMG SRC=\"images/smile.gif\" alt=\"\">"$content);
    
$content str_replace(":-)""<IMG SRC=\"images/smile.gif\" alt=\"\">"$content);
    
$content str_replace(":(""<IMG SRC=\"images/sad.gif\" alt=\"\">"$content);
    
$content str_replace(":-(""<IMG SRC=\"images/sad.gif\" alt=\"\">"$content);
    
$content str_replace(":o""<IMG SRC=\"images/icon_surprised.gif\" alt=\"\">"$content);
    
$content str_replace(":-o""<IMG SRC=\"images/icon_surprised.gif\" alt=\"\">"$content);
    
$content str_replace(":0""<IMG SRC=\"images/icon_surprised.gif\" alt=\"\">"$content);
    
$content str_replace(":D""<IMG SRC=\"images/bigsmile.gif\" alt=\"\">"$content);
    
$content str_replace(":-D""<IMG SRC=\"images/bigsmile.gif\" alt=\"\">"$content);
    
$content str_replace(":d""<IMG SRC=\"images/bigsmile.gif\" alt=\"\">"$content);
    
$content str_replace(":-d""<IMG SRC=\"images/bigsmile.gif\" alt=\"\">"$content);
    
$content str_replace(":p""<IMG SRC=\"images/icon_razz.gif\" alt=\"\">"$content);
    
$content str_replace(":-p""<IMG SRC=\"images/icon_razz.gif\" alt=\"\">"$content);
    
$content str_replace(":P""<IMG SRC=\"images/icon_razz.gif\" alt=\"\">"$content);
    
$content str_replace(":-P""<IMG SRC=\"images/icon_razz.gif\" alt=\"\">"$content);
    
$content str_replace(";)""<IMG SRC=\"images/wink.gif\" alt=\"\">"$content);
    
$content str_replace(";-)""<IMG SRC=\"images/wink.gif\" alt=\"\">"$content);
    
$content str_replace(":shocked:""<IMG SRC=\"images/shocked.gif\" alt=\"\">"$content);
    
$content str_replace(":rolleyes:""<IMG SRC=\"images/rolleyes.gif\" alt=\"\">"$content);
    
$content str_replace(":cool:""<IMG SRC=\"images/cool.gif\" alt=\"\">"$content);
    
$content str_replace(":angry:""<IMG SRC=\"images/angry.gif\" alt=\"\">"$content);
    
    return(
$content);
}
?>
As your posting the news / comment / anything your posting into the database, get the variable

$content = $_GET['content']; <-- that has been posted using a form
$content = smilies($content);

INSERT INTO...

Then once you pull it out of the database it will have the images One thing you need to look out for though are the slashes!

PHP Code:
$content $_GET['content'];
$content smilies($content);
addslashes($content); 
Then when drawing from the database in your "news" script:
PHP Code:
stripslashes($content);
echo(
"$content"); 
Hope that helps ya at all mate!

Last edited by feraira; 06-11-2005 at 08:30 AM.. Reason: PHP code
feraira is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Anyone familiar with str_replace(); ?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20174 seconds with 12 queries