Results 1 to 6 of 6

Thread: char replace

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    261

    Exclamation char replace

    hi
    im trying to change char in a text block but i cant get it to work.
    can somone please help
    the text is taken of another website and formatted. taking out any links and doubling " and ' so it can be added to my database (mysql)

    i got this
    PHP Code:
    $Temp strip_tags($plot[1], '<br>');
        
    $Temp2=str_replace('"','""',$Temp);
        
    $plott[1]=str_replace("'","''",$Temp2); 
    programming pc: laptop. running xp pro and vb.net..
    media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
    mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
    atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
    backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
    2 x video backup: atom 330, 2gb, 18tb harddrive
    everything on remote login..
    check out my builds http://AtomVaults.yolasite.com

    learning vb.net and php + mysql - got most of the basics now.

    I WISH THERE WAS MORE TIME IN THE DAY

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: char replace

    You're going to have to be more descriptive. What are you putting in (value of $plot[1] before your replacement code) and what are you getting out (value of $plott[1] at the end of your code)? You can help yourself troubleshoot by echo'ing out the results each step of the way:
    PHP Code:
    echo $plot[1] . "\n\n";
    $Temp strip_tags($plot[1], '<br>');
    echo 
    $Temp "\n\n";
    $Temp2=str_replace('"','""',$Temp);
    echo 
    $Temp2 "\n\n";
    $plott[1]=str_replace("'","''",$Temp2);
    echo 
    $plott[1] . "\n\n"
    At which point are you not getting what you expected for the output?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    261

    Re: char replace

    hi i solved my problem by using the following

    Code:
    $Find = array("'",'"');
                                 $ee =$plot[1], '<br>';
                                 $plot[1] =  str_replace($Find,"",$ee);
    programming pc: laptop. running xp pro and vb.net..
    media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
    mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
    atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
    backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
    2 x video backup: atom 330, 2gb, 18tb harddrive
    everything on remote login..
    check out my builds http://AtomVaults.yolasite.com

    learning vb.net and php + mysql - got most of the basics now.

    I WISH THERE WAS MORE TIME IN THE DAY

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    261

    Exclamation Re: char replace

    hi
    but now i have come across another problem with the same code..

    PHP Code:
    # Locations
      
    $locs $movie->locations();
      if (!empty(
    $locs)) {
        ++
    $rows;

        foreach (
    $locs as $loc) {
          if ( empty(
    $loc['url']) );
          else ;
          }

      }
       
    //this is the main txt im trying to filter this is from $ee
      //St. Luke's Hospital - 2632 E. Washington Street, Pasadena, California, USA
     //--- 

                                 
    $Find = array("'",'"');
                                 
    $ee =$loc['name'];
                                 
    $locationsname =  str_replace($Find,"",$ee); 
    when i use the txt im trying to filter direct in to the filter for example.
    PHP Code:
    $ee="St. Luke's Hospital - 2632 E. Washington Street, Pasadena, California, USA"
    the filter works but when im using the text direct from $loc['name']; the filter dont work
    programming pc: laptop. running xp pro and vb.net..
    media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
    mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
    atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
    backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
    2 x video backup: atom 330, 2gb, 18tb harddrive
    everything on remote login..
    check out my builds http://AtomVaults.yolasite.com

    learning vb.net and php + mysql - got most of the basics now.

    I WISH THERE WAS MORE TIME IN THE DAY

  5. #5
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: char replace

    .. wait. the entire point of all of this is to eventually add this data to the database, correct? don't use str_replace() at all then. use an escape function, like mysql_real_escape_string():
    PHP Code:
    $mysql_safe_loc mysql_real_escape_string($loc['name']); 
    then, use it in your query:
    PHP Code:
    $sql "INSERT INTO locations (name) VALUES ('{$mysql_safe_loc}');"
    Like Archer? Check out some Sterling Archer quotes.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    261

    Thumbs up Re: char replace

    hi kows
    i never thought to look at sql code. i have now changed it to the
    PHP Code:
    mysql_real_escape_string(); 
    and works perfect. it will take me some time to sort the rest of my code to this.

    thanks again kows you have been a big help on this as im still learning all this php coding
    programming pc: laptop. running xp pro and vb.net..
    media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
    mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
    atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
    backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
    2 x video backup: atom 330, 2gb, 18tb harddrive
    everything on remote login..
    check out my builds http://AtomVaults.yolasite.com

    learning vb.net and php + mysql - got most of the basics now.

    I WISH THERE WAS MORE TIME IN THE DAY

Posting Permissions

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



Click Here to Expand Forum to Full Width