Solved

PHP:  how to replace a VBCrLf to a break using str_replace

Posted on 2008-06-14
10
2,875 Views
Last Modified: 2013-12-13
I am trying to translate a line from ASP.NET with MSSQL to PHP with MySQL.

The original is:
bio = replace(RS("biography"),vbcrlf,"<br />")

I got to here:
$bio = str_replace("\n", "<br />", $row["biography"]);

but the breaks aren't showing.
In MySQL the entity shows line breaks.
How do I detect them?

help?
Thanks
0
Comment
Question by:Evan Cutler
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 21787510
try:
$bio = preg_replace('/(\r?\n)/', "<br />", $row["biography"]);
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 total points
ID: 21787535
please try this:
$search = array("\r\n", "\n", "\r");
$replace = '<br />';
$bio = str_replace($search, $replace,$row["biography"]);

Open in new window

0
 
LVL 9

Author Comment

by:Evan Cutler
ID: 21787570
no dice.
When I look at the output from MyPHPAdmin I can see the entries carraige return, but there is no visible symbols to indicate the carriage return.  

This is what it looks like in MySQL-MyPHPAdmin:
Ages:  All Ages
Medical School:  University of Kansas School of Medicine
Medical Degree:  MD
Board Certified:  Yes
Type of Board:  American Board of Family Practice

THis is what it looks like in the output:
Ages: 16 years and older Medical School: University of Connecticut Medical Degree: MD Board Certified: Yes Type of Board: American Board of Internal Medicine

help?
0
 
LVL 9

Author Comment

by:Evan Cutler
ID: 21787577
It also shows it like this:

<td valign="top">Ages:  12 years and older
Medical School:  University of Kansas School of Medicine
Medical Degree:  MD
Board Certified:  Yes
Type of Board:  American Board of Internal Medicine</td>

in the code.  Why does it not see that?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21787579
can you show the relevant php code you use to query + output  the data?
is the php file online so we can see the output?
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21787584
just to be sure: did you try out my suggestion also?
0
 
LVL 82

Accepted Solution

by:
hielo earned 200 total points
ID: 21787610
try:
$bio = preg_replace('/(\r\n|\n|\r|\f)/U', "<br />", $row["biography"]);
0
 
LVL 9

Author Comment

by:Evan Cutler
ID: 21787714
yep, tried both.  Here's my code:


	$SQL = "select physician_name,biography,photo_path from physicians";

	$SQL = $SQL . " where physician_id = " . $docid;

	//<!--#include file="/includes/validate.asp"-->

	include("../includes/appdata.php");

	$result = mysql_query($SQL) or die ("Error performing query: " .  mysql_error() . "<br>" . $SQL . "</td></tr>");

	$num_rows = mysql_num_rows($result);

	if ($num_rows == 0)

	{

		echo "No physician listings was found.";

	}

	else

	{

		while ($row = @mysql_fetch_array($result))

		{

			if (strlen($row["biography"]) <= 0 || $row["biography"] == NULL)

			{

				echo "<tr><td>No current biography exists for ". $row["physician_name"] .".</td></tr>";

			}

			else

			{ 

				$bio = preg_replace('/(\r\n|\n|\r|\f)/U', "<br />", $row["biography"]);

				?>

				

					<tr>

						<td <?PHP if (strlen($row["photo_path"]) > 0) { ?>colspan="2"<?PHP } ?> >

							<table cellpadding="0" cellspacing="0" border="0" width="100%">

								<tr>

									<td width="19"><img src="../images/headerArrow.gif" width="19" height="23" border="0" /></td>

									<td class="headerText" valign="middle" bgcolor="#B5CBDB"><strong><?PHP echo $row["physician_name"]; ?></strong></td>

								</tr>

							</table>

						</td>

					</tr>

					<tr>

						<?PHP if (strlen($row["photo_path"]) > 0) { ?>

							<td align="left" valign="top" width="150"><img src="../<?PHP echo $row["photo_path"]; ?>" width="139" height="132" hspace="3"></td>

						<?PHP } ?>

						<td valign="top"><?PHP echo $row["biography"]; ?></td>			

					</tr>			

						

				

				<?PHP

				

				

			}

	

		}

	}

	?>

	

	</table>

Open in new window

0
 
LVL 4

Assisted Solution

by:afzz
afzz earned 200 total points
ID: 21787777
change the code shown below
//change this

<?PHP if (strlen($row["photo_path"]) > 0) { ?>

                                                        <td align="left" valign="top" width="150"><img src="../<?PHP echo $row["photo_path"]; ?>" width="139" height="132" hspace="3"></td>

                                                <?PHP } ?>

                                                <td valign="top"><?PHP echo $row["biography"]; ?></td>                  

                                        </tr>                   
 

//into this

<?PHP if (strlen($row["photo_path"]) > 0) { ?>

                                                        <td align="left" valign="top" width="150"><img src="../<?PHP echo $row["photo_path"]; ?>" width="139" height="132" hspace="3"></td>

                                                <?PHP } ?>

                                                <td valign="top"><?PHP echo $bio; ?></td>                  

                                        </tr>                   

Open in new window

0
 
LVL 9

Author Closing Comment

by:Evan Cutler
ID: 31467296
Thanks Guys!!!
Awesome solutions.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
calculated column 12 74
How do I fix this error:  Warning: strpos(): Empty needle on line 122 3 15
WordPress syntax 2 25
Calculating number of days between two dates 7 31
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now