Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

111 users online



str_replace for smileys, and br's (HELP)

str_replace for smileys, and br's (HELP)

Currently viewing this thread: 1 (0 members and 1 guests)


Page 1 out of 2
Zeratul

Zeratul

kage
Status: Offline!

str_replace for smileys, and br's (HELP)

I have this code:

PHP:

<?php

            $theshout 
stripslashes($r['shout']);
            
$theshout str_replace('<''<'$r['shout']);
            
$theshout str_replace('>''>'$r['shout']);
            
$theshout str_replace(array_keys($smile), array_values($smile), $r['shout']);
            
$theshout str_replace('
'
'<br />'$r['shout']);

?>

When this displays the result, the smileys turn into text!
But the <br /> thingy is working just perfectly.

How will I solve this problem?

sabrina

sabrina

what could you possibly want to know about me?
Status: Offline!

Don't you want

PHP:

<?php

$theshout 
stripslashes($r['shout']);
$theshout str_replace('<''<'$theshout);
$theshout str_replace('>''>'$theshout);
$theshout str_replace(array_keys($smile), array_values($smile), $theshout);
$theshout str_replace('''<br />'$theshout);

?>


?

Zeratul

Zeratul

kage
Status: Offline!

Why?
So an empty space will become a line-break?
rofl

sabrina

sabrina

what could you possibly want to know about me?
Status: Offline!

It's just that in the code you have you keep setting $theshout to be
something new, overwriting what you just did with it.

I don't know why you replace empty spaces with breaks - it's your code!

Oh! You're wanting to replace newlines with breaks... you should have "\n" in the first term then... but you still keep overwriting what you just did (which was what my suggestion should hinder - I changed the last parameter in all the str_replace-calls).

Last edited by sabrina, July 20th, 2004 08:44 PM (Edited 1 times)

BigToach

BigToach

Neversidian
Status: Offline!

what do you mean the smilies are turing into text? can we see the $smile array. you need image tags around the imagepath

___________________

Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

Rad

Rad

thinking of something witty to put here
Status: Offline!
Quote:

Originally posted by sabrina
Don't you want

PHP:

<?php

$theshout 
stripslashes($r['shout']);
$theshout str_replace('<''<'$theshout);
$theshout str_replace('>''>'$theshout);
$theshout str_replace(array_keys($smile), array_values($smile), $theshout);
$theshout str_replace('''<br />'$theshout);

?>


?

Sabrina has the answer. The reason it worked for the last replace is that it kept resetting the variable until the last function. Listen to sabrina, she's a smart one Grin

sabrina

sabrina

what could you possibly want to know about me?
Status: Offline!

Haha, thanks Radley!
Coming from you, that is a very nice compliment :}

Zeratul

Zeratul

kage
Status: Offline!

It doesn't work Sad
Ok, here's the code.

PHP:

<?php
$smile 
= array(
    
'\:\)' => '<img src="emoticons/smile.gif" alt="\:\)" />',
    
'\:\(' => '<img src="emoticons/sad.gif" alt="\:\(" />',
    
'\:\D' => '<img src="emoticons/biggrin.gif" alt="\:\D" />',
    
'\o\_\O' => '<img src="emoticons/blink.gif" alt="\o\_\O" />',
    
'\:\|' => '<img src="emoticons/mellow.gif" alt="\:\|" />',
    
'\B\-\)' => '<img src="emoticons/cool.gif" alt="\B\-\)" />',
    
'\^\_\^' => '<img src="emoticons/happy.gif" alt="\^\_\^" />',
    
'\:\P' => '<img src="emoticons/tongue.gif" alt="\:\P" />',
    
'\:lol\:' => '<img src="emoticons/laugh.gif" alt="\:lol\:" />',
    
':\ohmy\:' => '<img src="emoticons/ohmy.gif" alt=":\ohmy\:" />',
    
'\;\)' => '<img src="emoticons/wink.gif" alt="\;\)" />',
    
':\wub\:' => '<img src="emoticons/wub.gif" alt=":\wub\:" />',
    
':\mad\:' => '<img src="emoticons/mad.gif" alt=":\mad\:" />',
    
'\-\_\-' => '<img src="emoticons/sleep.gif" alt="\-\_\-" />',
    
'\:dry\:' => '<img src="emoticons/dry.gif" alt="\:dry\:" />',
    
'\:ninja\:' => '<img src="emoticons/ninja.gif" alt="\:ninja\:" />'
);
        
$query "SELECT * FROM s1 ORDER BY id DESC LIMIT 0, 10";
        
$result = @mysql_query($query);

        while (
$r = @mysql_fetch_array($result)) {
            
$theshout stripslashes($r['shout']);
            
$theshout str_replace('<''<'$theshout);
            
$theshout str_replace('>''>'$theshout);
            
$theshout str_replace(array_keys($smile), array_values($smile), $theshout);
            
$theshout str_replace('''<br />'$theshout);
            
$thename stripslashes($r['name']);
            
$thename strip_tags($r['name'], '');
            
$r['http'] = stripslashes($r['http']);
            
$r['http'] = strip_tags($r['http'], '');
            
$r['email'] = stripslashes($r['email']);
            
$r['email'] = strip_tags($r['email'], '');
            if (
$r['http'] == "") {
                
$web "none";
            } else {
                
$web "<a href=\"".$r['http']."\" title=\"Visit ".$thename."'s website\">";
            }
?>

EDIT: vbulletin parses the smiles Sad so I added extra slashes

Last edited by Zeratul, July 26th, 2004 12:21 AM (Edited 1 times)

aonic

aonic

Neversidian
Status: Offline!

you can us nl2br instead of
$theshout = str_replace('', '<br />', $theshout);

http://us2.php.net/nl2br

you might also want
http://us2.php.net/manual/en/function.htmlspecialchars.php

ya, and i dont kno why ur smilies dont work Sad

___________________

-Developer
-Forum Leader
-NeverNET

Last edited by aonic, July 26th, 2004 12:39 AM (Edited 1 times)

sabrina

sabrina

what could you possibly want to know about me?
Status: Offline!

As I misunderstood you before (with the newlines) I think you want

PHP:

<?php
$theshout 
str_replace('''<br />'$theshout);
?>


replaced with

PHP:

<?php
$theshout 
str_replace("\n"'<br />'$theshout);
?>

Edit:
or you could do what pureevil4 suggested.
/edit

I don't think that answers your question, though(?)

Anyway, what do you mean by doesn't work? Is it still the images?

Last edited by sabrina, July 26th, 2004 12:34 AM (Edited 1 times)

Page 1 out of 2
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0122 seconds.