• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

Problems w/ str_replace()

Howdy

I'm using the following code to open a file and read it one line at a time:

$Seq_File = fopen("/home/websites/genework/html/DATA/$Motif", "r");
while (!feof($Seq_File))
{
      $line = fgets($Seq_File);
      str_replace('{','<b>',$line);
        str_replace('}','</b>',$line);
...
...

Here's the sequence it's getting from the file:

TCTTCGTCTTCTAACAGAGAATGGTCATCATCTTTATTACTGTCGCCAAAGGTGGATTGTCCAAGTAAAA
CCTTTTCCCTTTTAGAAGCAAAATCATCAACTTCGTTTAAACCATACGGATTAATCTCATCCCCAACTTC
AGAGGTCTTAGTTCTGTTTGAGCCTTTGCGTACCATATTATTCTATACACCCACTCTAATATGTTTTCTC
TTCCTCCAAAACTTTTTGTATAAAAGCATCAGTGAGATGAGCTATGATGAGATGAGCTTCATTATTGAA{
TTTTTT}TTCATTGCAGAAGCGCAGTTTGAAAATTTTTCATCCGCCCTGCAAAGTCCAA{TTTTTT}GAT
CAGCAGAAGATAATGACCAGAGAATTATGGTATTCAAGAGAACAATTCAAAAGAGGACAGCTAGAAAGAT
ATTGAGGTATTTATAATTTGCTAGACTAACCGAAAGTCGAAGCGTAATCTTG{TTTTTT}ATTAAGCGGG
ATAGCATTCATTAAGT

The end of each line includes a \n and I'm wondering if this is why the str_replace() I'm attempting isn't working.  
0
cdromes
Asked:
cdromes
1 Solution
 
ezatonCommented:
Do not use the curly brackets like that. Use it like this:
str_replace('\{','<br>',$line);

Hope it solves the problem.
0
 
cdromesAuthor Commented:
The answer was actually something  missed on the MAN pages....PHP doesn't save the converted string into the same variable, so you need to provide a destination variable.  So, this worked:

$line = fgets($Seq_File);
$line1 = str_replace('{','<b>',$line);
$line2 = str_replace('}','</b>',$line1);

$line2 ends up having the tags in the right places.
0
 
Vee_ModCommented:
Closed, 125 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now