Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Simple string replace in php

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 30-11-2009
Member
 
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.

Reply With Quote
  #2  
Old 30-11-2009
Member
 
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.
Reply With Quote
  #3  
Old 30-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
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.
Quote:
$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.
Reply With Quote
  #4  
Old 30-11-2009
Member
 
Join Date: May 2008
Posts: 2,383
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.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 07:26 AM.