jeudi 23 février 2017

PHP if statement not working in preg_replace

I have a simple PHP of statement but it keeps giving me 'Internal 500'. Can anyone see what is wrong with this code?

(It works without the 'if')

$fullyfiltered = preg_replace('/<span>(.*?)<\/span>/', '<div class="chat-message ' if('$1'=="MichaelD"){'me'}else{'chat-midnightblue'}'"><div class="chat-contact"><img src="/assets/demo/avatar/tswan.png" alt=""></div><div id="chat-text" class="chat-text">$1: ', $nearlyfiltered);

EDIT - Full script:

                                        <script>
                                    setInterval(function(){
                                        document.getElementById('chat-text').innerHTML = '';
                                        <?php
                                                $fh = fopen('chat.txt','r');
                                                while ($line = fgets($fh)) {
                                                  //echo "<p>" . $line . "</p>";
                                                  $filtered = str_replace("'", "\\'", $line);
                                                  $almostfiltered = str_replace("<span></span>\n", "", $filtered);
                                                  $nearlyfiltered = trim(preg_replace('/\s\s+/', ' ', $almostfiltered));
                                                  $fullyfiltered = preg_replace('/<span>(.*?)<\/span>/', '<div class="chat-message ' if('$one'=="MichaelD"){'me'}else{'chat-midnightblue'}'"><div class="chat-contact"><img src="/assets/demo/avatar/tswan.png" alt=""></div><div id="chat-text" class="chat-text">$1: ', $nearlyfiltered);
                                                  if(!empty($fullyfiltered)){
                                                    $endingp = "</div></div>';"; 
                                                  } else {
                                                    $endingp = "';";
                                                  }
                                                  echo "document.getElementById('chat-text').innerHTML = document.getElementById('chat-text').innerHTML + '" . $fullyfiltered . $endingp;
                                                }
                                                fclose($fh);
                                            ?>      
                                    },5000);
                                    </script>

Aucun commentaire:

Enregistrer un commentaire