Let me attempt to explain my problem. I have a crude php script that
takes a text list of songs that was generated by an mp3 list program and
translates each entry into the form where they can be inserted into my
mySQL database in the proper fields although it is currently being
written to another text file because of the problem I have below. The
lines from the mp3 text file will look like this:
Al Green - The Supreme Al Green - 01 - Tired Of Being Alone.mp3
5.04MB 244k
Al Green - The Supreme Al Green - 02 - I Can't Get Next To You.mp3
6.52MB 242k
Al Green - The Supreme Al Green - 03 - Let's Stay Together.mp3
5.74MB 242k
The script reads it into an array and keys on the "-" to explode it. The
script works just fine on those, doing what I want it to and putting
everything into it's proper field. But my problem comes into play when
there is more than the three dashes in any selection like:
Al Green - The Supreme Al Green - 12 - Sha-la-la (Make Me Happy).mp3
6.05MB 283k
That totally wrecks havoc with what I need the script to do. How can I
modify the script to ignore any dashes (should there be any) after the
third one? Once I can get this bug worked out I can change from writing
to another textfile to inserting directly in the database. Thanks for
any help.
The PHP scripting I'm using is:
<?php
// Get the info
$q = @$_POST['q'] ;
$trimmed = trim($q); //trim whitespace from the stored variable
$dir = "e:/mirc/CDLists/";
$file = ($dir . $q);
//used to strip the last two items from array (size and bitrate)
function stripLast2($arr ayData){
$elements=explo de(" ",$arrayDat a);
$returnString = "";
for
($i=0;$i<count( $elements)-4;$i++){$return String.=$elemen ts[$i]." "; }
return $returnString;
}
//reads song list identified in $trimmed into array
function read_songlist($ file)
{
if (!file_exists($ file))
{
echo "Doesn't exist\n";
return false;
}
$fd = @fopen($file, 'r');
if (!is_resource($ fd))
{
echo "Error reading $file\n";
return false;
}
$path = ($file);
$album = basename($path, ".txt");
$album = mysql_escape_st ring( $album );
$ID = "";
$ret = array();
while ($line = fgets($fd, 4096))
{
$arrayData = explode("-", trim($line));
$test1 = @$arrayData[3];
$test1 = stripLast2($tes t1); //strips last two items from the arrayData[3]
$songData = explode(" ", @$arrayData[3]);
$ar=array_rever se($songData); //reverses array so I can handle last two
items in right place
$track = mysql_escape_st ring( trim($line) );
if (strlen($track) > 0)
$ret[] = @sprintf("INSER T INTO `lists` VALUES(\"%s\", \"%s\",
\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\");",$I D, $album,
$arrayData[0], @$arrayData[1], @$arrayData[2], $test1, @$ar[2], @$ar[0]);
}
fclose($fd);
return $ret;
}
//the html part to display the text box to enter the filename
echo "<p align='center'> <br><b>Please enter the filename and extension
to be entered into the database text file...</b><br><br></p>";
?>
<div align="right">
<form name="form" action="<? print $_SERVER['PHP_SELF'] ?>" method="post">
<input type="text" name="q" />
<input type="submit" name="Submit" value="Filename " /><span
style="font-family:Verdana, Arial,Helvetica ,sans-serif;"> ex:
Albums010.txt</span>
</form>
</div>
<?php
//writes results to html page
$inserts = read_songlist($ file);
if (is_array($inse rts))
{
foreach($insert s as $idx => $sql)
echo $sql . "\n";
} else echo "error\n";
//writes results to new textfile
$filename = 'e:\mirc\CDList s\database.txt' ;
$fp = fopen($filename , "a");
if (is_array($inse rts))
{
foreach($insert s as $idx => $sql)
fwrite($fp,stri pslashes("$sql\ n"));
}
fclose($fp);
?> 2 2015
JackM wrote: Let me attempt to explain my problem. I have a crude php script that takes a text list of songs that was generated by an mp3 list program
and translates each entry into the form where they can be inserted into
my mySQL database in the proper fields although it is currently being written to another text file because of the problem I have below. The
lines from the mp3 text file will look like this:
Al Green - The Supreme Al Green - 01 - Tired Of Being Alone.mp3 5.04MB 244k Al Green - The Supreme Al Green - 02 - I Can't Get Next To You.mp3 6.52MB 242k Al Green - The Supreme Al Green - 03 - Let's Stay Together.mp3 5.74MB 242k
The script reads it into an array and keys on the "-" to explode it.
The script works just fine on those, doing what I want it to and putting everything into it's proper field. But my problem comes into play
when there is more than the three dashes in any selection like:
Al Green - The Supreme Al Green - 12 - Sha-la-la (Make Me Happy).mp3 6.05MB 283k
That totally wrecks havoc with what I need the script to do. How can
I modify the script to ignore any dashes (should there be any) after
the third one? Once I can get this bug worked out I can change from
writing to another textfile to inserting directly in the database. Thanks for
any help.
The PHP scripting I'm using is: <?php // Get the info $q = @$_POST['q'] ; $trimmed = trim($q); //trim whitespace from the stored variable $dir = "e:/mirc/CDLists/"; $file = ($dir . $q);
//used to strip the last two items from array (size and bitrate) function stripLast2($arr ayData){ $elements=explo de(" ",$arrayDat a); $returnString = ""; for ($i=0;$i<count( $elements)-4;$i++){$return String.=$elemen ts[$i]." "; } return $returnString; } //reads song list identified in $trimmed into array function read_songlist($ file) { if (!file_exists($ file)) { echo "Doesn't exist\n"; return false; }
$fd = @fopen($file, 'r'); if (!is_resource($ fd)) { echo "Error reading $file\n"; return false; }
$path = ($file); $album = basename($path, ".txt");
$album = mysql_escape_st ring( $album ); $ID = "";
$ret = array();
while ($line = fgets($fd, 4096)) { $arrayData = explode("-", trim($line));
$test1 = @$arrayData[3]; $test1 = stripLast2($tes t1); //strips last two items from the
arrayData[3] $songData = explode(" ", @$arrayData[3]);
$ar=array_rever se($songData); //reverses array so I can handle last
two items in right place
$track = mysql_escape_st ring( trim($line) ); if (strlen($track) > 0) $ret[] = @sprintf("INSER T INTO `lists` VALUES(\"%s\",
\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\");",$I D, $album, $arrayData[0], @$arrayData[1], @$arrayData[2], $test1, @$ar[2],
@$ar[0]); } fclose($fd); return $ret; }
//the html part to display the text box to enter the filename echo "<p align='center'> <br><b>Please enter the filename and
extension to be entered into the database text file...</b><br><br></p>";
?> <div align="right"> <form name="form" action="<? print $_SERVER['PHP_SELF'] ?>"
method="post"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Filename " /><span style="font-family:Verdana, Arial,Helvetica ,sans-serif;"> ex: Albums010.txt</span> </form> </div> <?php
//writes results to html page $inserts = read_songlist($ file); if (is_array($inse rts)) { foreach($insert s as $idx => $sql) echo $sql . "\n"; } else echo "error\n";
//writes results to new textfile $filename = 'e:\mirc\CDList s\database.txt' ; $fp = fopen($filename , "a"); if (is_array($inse rts)) { foreach($insert s as $idx => $sql) fwrite($fp,stri pslashes("$sql\ n")); } fclose($fp); ?>
maybe use " - " (note the spaces) instead of "-" as separator for
explode?
micha
chotiwallah wrote: maybe use " - " (note the spaces) instead of "-" as separator for explode?
micha
Duh! Just what I needed.
Thanks micha. Sometimes I can't see the forest for the trees. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andy Cunningham |
last post by:
Hi all,
Has anyone seen a problem like this before:
http://80.177.2.28/phpinfo.php
This is a webserver on my home PC, and when viewed from there it looks
fine. However, from computers across the internet, the page
'explodes' halfway down, but in different places each time (if it
loads OK try hitting refresh). I'm fairly sure the PHP code is not
the problem, as this same problem occurs with the phpinfo page, with a
|
by: mark |
last post by:
I have an array as follows
$sounds = array();
$sounds = "fishes/1/sound.php";
$sounds = "fishes/2/sound.php";
$sounds = "fishes/3/sound.php";
$sounds = "fishes/4/sound.php";
$sounds = "fishes/5/sound.php";
$sounds = "bears/1/sound.php";
|
by: Nathan Rose |
last post by:
Here's my problem. I am reading from a text file using this:
if (!file_exists($file))
{
echo "Don't exist\n";
return false;
}
$fd = @fopen($file, 'r');
if (!is_resource($fd))
|
by: KellyH |
last post by:
Hi, I hope someone can point me in the right direction.
I'll get it out of the way: Yes, I am a college student. No, I am not
looking for anyone to do my homework, just looking for help. I have been
reading this ng all semester, and found it very helpful. I just have a
stupid problem going on right now.
Here's the project:
We have to make a little frame with a text field, where the user inputs a
number, and a text area where a...
|
by: Jesphachia Twhongle |
last post by:
A year ago, it would have been a tragedy to lose Munich to string pulling by
Microsoft Insiders who want tacquiredt Linux.
Obviously, the forces of corruption, evil and lying have raised their head,
and are trying to forestall the inevitable.
But this is a different year.
The 2.6 is a roaring success.
| |
by: Tommy Lang |
last post by:
I am working on this project and I need some help/pointers/comments to
get me started, I am stuck.
The program will be used to store information in an array while it is
running.
I need to store objects of my classes Person(superclass),
Student(inherit Person), Teacher(inherit Person) in that array.
The name will be the unique key. These classes are all working ok. I
want to be able to add, remove, find etc. objects.
To all of this, I...
|
by: vinod.bhavnani |
last post by:
Hello all,
I need desperate help
Here is the problem:
My problem today is with multidimensional arrays.
Lets say i have an array A this is a 4 dimensional
static array.
|
by: gcary |
last post by:
I am having trouble figuring out how to declare a pointer to an array
of structures and initializing the pointer with a value. I've looked
at older posts in this group, and tried a solution that looked
sensible, but it didn't work right. Here is a simple example of what
I'm trying to accomplish:
// I have a hardware peripheral that I'm trying to access
// that has two ports. Each port has 10 sequential
// registers. Create a...
|
by: SpreadTooThin |
last post by:
If you are deriving a new class from another class,
that you must (I assume) know the initializer of the other class.
So in myClass
import array
class myClass(arrary.array):
def __init__(self, now here I need to put array's constructor
parameters..., then mine):
array.array.__init__(self, typecode)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |