LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-28-2004, 10:48 PM   #1
antony_csf
Member
 
Registered: Jun 2004
Posts: 51

Rep: Reputation: 15
php question - how can i replace the content?


inseide $this->content [contains html code]
===================================
token
/* HINTS : hint 1*/

import java.io.*;
class IOTest {
public static void main (String[] args) {
try{
BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
String response;
System.out.println ("What is your favorite programming language?");
response = stdin.readLine();
System.out.println ("You have great taste. " + response + " is a great language");
}catch(IOException ioe){
// ioe
}
}
}

token
===================================

i would like to replace all content between token to a word "replaced"

ereg_replace("^token(.*)token$", "replaced", $this->content);

however it won't work !! I think my regexp is worng !

anyone can fix this problem?


expected outcome
===================================
replaced
===================================

thx
 
Old 06-29-2004, 11:19 AM   #2
zeropash
Member
 
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
I think the code is fine. I think the problem is that you are still echoing the content string.
you should be echoing the return value of ereg_replace.

I tried the following script and it works fine.

#!/usr/bin/php

<?php

$content='token
blah blah blah
token';

echo ereg_replace('^token(.*)token$', 'replaced', $content) . "\n";
?>
 
Old 06-29-2004, 08:01 PM   #3
antony_csf
Member
 
Registered: Jun 2004
Posts: 51

Original Poster
Rep: Reputation: 15
thx!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace text of unknown content with other text in file brian0918 Programming 15 07-14-2005 09:22 PM
Replace text of unknown content with other text in file brian0918 Linux - Software 1 07-14-2005 03:22 PM
PHP string replace question. apt Programming 1 04-26-2005 07:47 PM
how to replace html-file-content ??? ledauphin Linux - Newbie 2 03-08-2004 04:37 PM
php content management sridharinfinity Linux - General 1 11-04-2003 05:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration