SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict AdRock952's Avatar
    Join Date
    Aug 2006
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg_replace refuses to work properly

    I have been tearing my hair out all day with this and it's driving me nuts.

    There is no reason why this preg_replace refuses to work properly because the code is exactly the same on my localhost (testing machine) as is on the hosted server.

    It works fine here so why not online?

    It replaces any instance of <ul> and <br> but not the images

    PHP Code:
    function convert_text($content) {
        
    $reg_ex = array(
            
    '/<ul>/s',
            
    '/.jpg">/s',
            
    '/.gif">/s',
            
    '/<br>/s'
        
    );
        
        
    $replace_word = array(
            
    '<ul class="list">'
            
    '.jpg" class="imgright" alt="" />'
            
    '.gif" class="imgright" alt="" />',
            
    '<br />'
        
    ); 
        
        
    $content preg_replace($reg_ex$replace_word$content);
            
        return 
    $content;

    an example of a string i am trying to convert is
    <img src="http://www.images/hailingstar.jpg"><br>

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Location
    Athens, Greece
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe it does not work online because of magic_quotes?

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have not posted something which demonstrates the problem. Your issue is not with the code/sample string you posted.

    For example, this would demonstrate your problem. But, this works properly.
    PHP Code:
    var_dump(convert_text('<img src="http://www.images/hailingstar.jpg"><br>')); 

  4. #4
    SitePoint Addict AdRock952's Avatar
    Join Date
    Aug 2006
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried using a var_dump and i doesn't work if i use the string used from the posted variable.

    If i var_dump a string straight into the function it works so i don't know why the posted variable doesn't work

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That would indicate the variable contains a different value. 01globalnet suggested a strong possibility.

  6. #6
    SitePoint Addict AdRock952's Avatar
    Join Date
    Aug 2006
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just looked at phpinfo of the server and magic_quotes_gpc is turned on.

    Could this be the problem and if it is how do i get around it?

  7. #7
    SitePoint Addict AdRock952's Avatar
    Join Date
    Aug 2006
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used stripslashes and it seemed to work


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •