-
Posts
4 -
Joined
-
Last visited
Never
Posts posted by Pipes
-
-
I know this is probably a hugely simple thing for an experienced programmer to see, but I'm just not at the moment...basically I've got a file of quotes that are split in the .txt file as so:
"Quote in quotations then" - Author <<<<<
I would like to write a script that splits the authors from the quotes. Here is where I'm at:
[code]$quotesfile = "http://localhost/projects/quotes_list/quotes.txt";
$handle = fopen($quotesfile, 'rb');
$quotes = fread($handle, 1024);
$pattern = '/\"[A-Za-z0-9]\"/';
$quotes = preg_split($pattern, $quotes);
print_r($quotes);[/code]
This prints out as follows:
Array ( [0] => "We're going to go pull the call girl cards out of phone boxes." - Lisa Pruden "I think I left lippy on you." - Olga Bof "In the end I just pretended to take it, and then spat it out later" - Sasha Breslau "He likes a bit of chav." - Lauren Dunn "She responds well to Toblerone." - Stephen Hardingham "Everything in the world is on my little pink stick." - Jon Holmes "I'm not sure I want a wanking cat on a Friday afternoon." - Dom Eames "I like the idea of extreme cunninglingus." - Mandy Pollard "I'm trying to think of a retort to say I've got a huge cock, but I can't." - Scott Dingley "It's a man's place Lelia. It's supposed to be dirty." - Jon Salt "Do you want me to sit on you?" - Emma Williams "I don't dream about badgers." - Mark Limb "Did no-one see I just punched that girl? I feel like a wife beater." - Jon Salt The quotes list says goodbye to Paul "temple of meat" Sigaloff. Here are Paul's best bits: "I have to manage my own expectations." "Ok good - let's have a meeting, but don't )
I have tried a couple variations of a while and foreach loop, but each time I try one, I get no results at all. Either I get :
Array ( [0] => )
or there are no results whatever.
Can anyone let me know how to use the preg_split better so as to store the quotes and authors into the keys and values of an array, so that I can work with them more easily?
Any advice greatly appreciated! :-\
Andy -
Thanks Ken: sorry should have mentioned line 15 is the one that begins
$quotestxt = '$DOCUMENT_ROOT/quotes.txt';
I have now changed this to double quotes, but the problem persists.
The location and path is correct (I created a short variable name for the server path above this code.) so I don't know what variable problems to be looking for??
Thanks for trying to help.
best, Andy
-
Hello: I'm a complete novice trying to split a file of quotations into quotes and authors (it's a .txt file). I've written this short simple script but i'm getting an error message.
[code]$quotestxt = '$DOCUMENT_ROOT/quotes.txt';
$quotes_file = fopen($quotestxt, 'r+');
while (fread($quotes_file, 1024)) {
$pattern = '^[\"]';
$quote_roster = preg_match($pattern, $quotes_file);
print_r($quote_roster);
}
[/code]
Th error message is telling me: Parse error: parse error, unexpected T_VARIABLE in C:\XXXX\separate_quotes_from_authors.php on line 15
can anyone tell me what I should looking for? i've tried the manual, but I can't seem to help myself. It's driving me mad!
any help appreciated!
Pipes
Most Popular Words List: Help?
in PHP Coding Help
Posted
thanks in advance. Andy
[code]<?php function most_used_words_cloud()
{
// display most used words
// set global variable, so we can test later if this is on the page
$sql = "SELECT quote FROM quotes";
$result = mysql_query($sql);
/**
* If we got here, we know that the $result variable
* contains a resource identifier through which
* we can loop through the rows returned and
* display the row fields
*/
$unique_words = array();
while ($record = mysql_fetch_array($result))
{
$words = preg_split("/[\W]+/", $record[1]);
foreach ($words as $word) {
/** weed out words that are fewer than three letters long */
if (strlen($word) < 3) {continue;}
if (array_key_exists($word, $unique_words))
{
/** shorthand for increasing value of $word by one if $word exists in $unique_words */
$unique_words[$word]++;
}
else {
/** initialize the counter to 1 for this word */
$unique_words[$word] = 1;
// converts number of occurrences into big/small font
$num_words = count($unique_words);
$unique_word_keys = array_keys($unique_words);
foreach ($unique_word_keys as $unique_word_value)
{
$num_occurrences = $unique_words[$unique_word_value];
//if ($num_occurrences < 10) continue;
$size = 10 + ($num_occurrences / 2);
echo "<span style=\"font-size: $size\">$unique_word_value</span> ";
}
}}}}?>[/code]
sorry about the rubbish strange marks as tabs, don't know how to get rid of them.