Results 1 to 4 of 4

Thread: Simple string replace in php

  1. #1
    Join Date
    Nov 2009
    Posts
    446

    Simple string replace in php

    Hi
    I Have created a .html template file. I have even created a title to add in the link to it. This is the same as the title of the page. But I want to do something and replace it so it becomes more user friendly. I can not find any solution for it. I am posting my code below, See if you can help me.
    Code:
    $file_show=str_replace("{title2}",$line['title'],$file_show);
    
    makes {title2} work through the template, but stuff like
    
    $title2=str_replace(" ","-",$title2);
    Please help. Thanks in advance.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Simple string replace in php

    Hello
    Sorry bro, I can not follow your code today because I am very busy in my other works. But i have a code related to your problems. So I have posted the code below. Just go through it, see that may help you.

    Code:
     $title=$getinf['title'];
          $title=strrep('.',' ',$title);
         $title=strrep('?',' ',$title);
         $title=trim ($title); //trims the blank space at the beginning and end of string
    
    $title=strrep(' ','-',$title);
    echo "<a href=".$getinf['id'] ."/". $title . ".html" . "><small>Read More</small></a>";
    any more queries then do post back.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Simple string replace in php

    Hi
    I read your code / program and tried to understand what you are trying to do, but unfortunately I did not understand what are you exactly trying to achieve in your program. Firstly the $title2 is undefined. I am not sure what you are trying to do, but I am posting an example see this may help you.
    $file_show=strrep("{title2}",$line['title'],$file_show);

    $file_show=strrep(" ","-",$file_show);
    I think this is what you are trying do. If you have queries then do post back again.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Simple string replace in php

    Hi
    I have no idea what are you trying to do in your program. I think your full source code would be much better for understanding. Still, here you are trying to create new meta title and you are looking to remove the characters from there. This is what you are doing.
    Code:
    $title2 = preg_replace('/[^a-z^A-Z^]/', ' ', $title2);
    If you want to keep numbers then you can try this.
    Code:
    $title2 = preg_replace('/[^a-z^A-Z^0-9^]/', ' ', $title2);
    You could possible run that prior to your final output.

Similar Threads

  1. Replace backslash in a string
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 05:43 AM
  2. Regex replace an integer with string
    By New ID in forum Software Development
    Replies: 5
    Last Post: 05-02-2010, 01:35 AM
  3. Find and Replace in JavaScript String
    By Wilbur in forum Software Development
    Replies: 5
    Last Post: 15-12-2009, 02:23 PM
  4. Replace a string in multiple files Linux
    By ADISH in forum Tips & Tweaks
    Replies: 0
    Last Post: 27-06-2009, 10:07 AM
  5. Replace text string using batch file
    By jean-paul martell in forum Operating Systems
    Replies: 2
    Last Post: 23-06-2009, 01:18 PM

Tags for this Thread

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
  •  
Page generated in 1,727,402,524.83952 seconds with 17 queries