Solved

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

Posted on 2008-06-14
10
2,860 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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]
Comment Utility
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 142

Expert Comment

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

Accepted Solution

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

Author Comment

by:Evan Cutler
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Guys!!!
Awesome solutions.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 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

12 Experts available now in Live!

Get 1:1 Help Now