Jump to content

Recommended Posts

hi,

can anyone please tell me how can i echo a string

in a specific column position.

i have $str1, $str2 and $str3.

i like to place the $str3 in 1-6 with a length of 6

and $str2 in 7-12 with a length of 6

and $str1 in 13-17 with a  length of 5.

 

please advice what functions or how can i achieved this

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/134150-echo-str-in-a-specific-column/
Share on other sites

my output file layout:

COLUMNS	LENGTH	DESCRIPTION

1-6	6	DIRECTORY CODE
7-12	6	HEADING CODE
13-17	5	UDAC
18-107	90	LISTING NAME
108-197	90	ADDRESS
198-222	25	CITY
223-224	2	STATE
225-229	5	zc
230-232	3	AREA CODE
233-239	7	TELEPHONE NO.
240	1	NUMBER OF INDENT TEXT
241-318	78	TN/TM/CTM NAME
319-418	100	INDENT 1 TEXT
419-518	100	INDENT 2 TEXT
519-618	100	INDENT 3 TEXT
619-718	100	INDENT 4 TEXT
719-818	100	INDENT 5 TEXT
819-918	100	INDENT 6 TEXT
919-1018	100	INDENT 7 TEXT

 

my echo is:

DirCode:002 Listing Name: NEW LIFE PREGNANCY CENTER Address: 1779 N ALVERNON WAY City: TUCSON State:  ZipCode:  Email Add: WWW.NEWLIFEPREGNANCYCENTERS.ORG Phone: 5207957541 Heading No: 4109 UdacCode: 4HS1 UdacRate: 1992.00
DirCode:002 Listing Name: WOMEN'S PREGNANCY CENTERS Address: 2290 E SPEEDWAY (CENTRAL) City: TUCSON State:  ZipCode:  Email Add: WWW.WPCTUCSON.COM Phone: 5206225774 Heading No: 4109 UdacCode: ABLN UdacRate: 0.00
DirCode:002 Listing Name: WOMEN'S PREGNANCY CENTERS Address: 2290 E SPEEDWAY (CENTRAL) City: TUCSON State:  ZipCode:  Email Add: WWW.WPCTUCSON.COM Phone: 5206225774 Heading No: 4109 UdacCode: TQCWP UdacRate: 6480.00
DirCode:002 Listing Name: OLD PUEBLO FAMILY PLANNING Address: 5240 E KNIGHT DR STE 112 City: TUCSON State:  ZipCode:  Email Add:  Phone: 5203239682 Heading No: 5556 UdacCode: ABLN UdacRate: 0.00
DirCode:002 Listing Name: OLD PUEBLO FAMILY PLANNING Address: 5240 E KNIGHT DR STE 112 City: TUCSON State:  ZipCode:  Email Add:  Phone: 5203239682 Heading No: 5556 UdacCode: QC1 UdacRate: 2160.00
DirCode:002 Listing Name: DEMBOWSKI LAWRENCE S CPA Address: 405 W COOL DRIVE # 103 City: TUCSON State:  ZipCode:  Email Add:  Phone: 5202977

 

my code is:

$dir = $_POST['dir'];
move_uploaded_file($_FILES["file"]["tmp_name"],"tmp/".$_FILES["file"]["name"]);
$filename1 = $_FILES["file"]["name"];
$rowP1 = 1;
$count = 0;
$ext = explode(".", $filename1);

if($ext[1] == "csv")
{
	if ($_FILES["file"]["name"] == NULL) {
				//DO NOTHING
		} else {
				//IMPORT QUERY TO COURSE TABLE
			$handle1 = fopen ("tmp/".$filename1, "r" );

			while ( ($data = fgetcsv ( $handle1, 1000, "," )) !== FALSE ) {
				echo "<strong>DirCode:</strong>" . $dir  . " ";
				echo "<strong>Listing Name:</strong>" . " " . $data[1] . " ";
				echo "<strong>Address:</strong>" . " " . $data[2] . " ";
				echo "<strong>City:</strong>" . " " . $data[3] . " ";
				echo "<strong>State:</strong>" . " " . $data[4] . " ";
				echo "<strong>ZipCode:</strong>" . " " . $data[5] . " ";
				echo "<strong>Email Add:</strong>" . " " . $data[6] . " ";
				echo "<strong>Phone:</strong>" . " " . str_replace("-","",$data[7]) . " ";
				echo "<strong>Heading No:</strong>" . " " . $data[8] . " ";
				echo "<strong>UdacCode:</strong>" . " " . $data[10] . " ";
				echo "<strong>UdacRate:</strong>" . " " . $data[11] . "<br>";

			$count++;
						}
			$rowP1 = 0;
			}
			echo  $count . " " . "Records successfully added";
			fclose ( $handle1 );

}else{
	echo "Invalid File Format";

}

 

i need my echo to be in the position of the file layout (same column and length)

 

please....tnx

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.