homer.favenir Posted November 25, 2008 Share Posted November 25, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/134150-echo-str-in-a-specific-column/ Share on other sites More sharing options...
premiso Posted November 25, 2008 Share Posted November 25, 2008 Be more descriptive, what type of column? A database column, an array. What does 1-6 represent? Is it random what $str3 would be in? like it could be 4 one time or 5 the next? More descriptive and code would help. Quote Link to comment https://forums.phpfreaks.com/topic/134150-echo-str-in-a-specific-column/#findComment-698307 Share on other sites More sharing options...
jordanwb Posted November 25, 2008 Share Posted November 25, 2008 To me it seems like he wants to make a table out of ASCII. Quote Link to comment https://forums.phpfreaks.com/topic/134150-echo-str-in-a-specific-column/#findComment-698308 Share on other sites More sharing options...
homer.favenir Posted November 25, 2008 Author Share Posted November 25, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/134150-echo-str-in-a-specific-column/#findComment-698330 Share on other sites More sharing options...
jordanwb Posted November 25, 2008 Share Posted November 25, 2008 I'm not exactly sure what's going on in your code, but you can use <pre></pre> tags to preserve spacing. Then use strlen and pad the strings until they're the correct length. Quote Link to comment https://forums.phpfreaks.com/topic/134150-echo-str-in-a-specific-column/#findComment-698625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.