Jump to content

Rahul Dev

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Rahul Dev's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello guys i have a problem while inserting a string to db. The string is cut out and only part of it is inserted and the string is not trimmed my code: <?php require ('dbconnect.php'); $text = "Maltraitance : Shirin Aumeeruddy-Cziffra réclame la fermeture de la crèche «Le Nid» de Sodnac "; $newString = preg_replace('/^[a-zàâçéèêëîïôûùüÿ]*$/i', ' ', $text); $newString2 = trim($newString); echo $newString2; $sql = "INSERT INTO test VALUES('".$newString2."')"; $result = mysql_query($sql); ?> The part that is inserted is: Maltraitance Shirin Aumeeruddy Cziffra r As you can see there's an additional space and the string is not complete Any1 can help??
  2. Hello guys i have a problem when i screen scrape a piece of text from a url and save it to my db. The text is in french and contains special characters like é. so when i screen scrape it i receive it in this form &eacute. e.g i have a word région in the website but when i screen scrape it, it becomes région. The reason that i want to store it as it is displayed is that i need to perform some operations on the text after saving it in the db as i want. Is there any way to store the screened scrape text in the form that it is displayed or convert it to the way i want(like this - région) my code is as follows: $html = file_get_dom('http://www.defimedia.info/news/8425/Grosses-averses-%3A-les-pompiers-inond%C3%A9s-d%E2%80%99appels-'); foreach($html->find('div[class=PostContent]') as $element) { $tags = array('<div class="PostContent">', '<!-- The Adsense will automatically be inserted half way through the content. Applies for both Side and Middle options. -->', '<font face="Georgia">', '<font size="2">', ''); $new_element = str_replace($tags, "", $element); $sql1 = "UPDATE articles SET original_text = '" . mysql_real_escape_string($new_element) . "' WHERE article_id = '$item_id'"; $result1 = mysql_query($sql1) or die('Query failed: ' . mysql_error()); }
  3. Hello, i need to send emails to users according to the category they have selected everything works fine except for the mail function which tells me that i cannot parse an array variable. the error code is: Warning: mail() expects parameter 1 to be string, array given in C:\wamp\www\newsletter.php on line 25 can any1 tell me how i can send the mail so that it accepts that variable? my code is: <?php $db_hostname="localhost"; $db_username="root"; $db_password=""; $db = mysql_connect($db_hostname,$db_username,$db_password); if (!$db) { die("Could not connect: " . mysql_error()); } mysql_select_db("newsletter", $db); if (isset($_POST['categories'])) { //make the checkmarks with name categories[] foreach ($_POST['categories'] as $cat) { $email_query = mysql_query("SELECT email FROM members WHERE `category` = '" . $cat . "'"); if (mysql_num_rows($email_query)) { while ($email = mysql_fetch_array($email_query)) { ini_set('SMTP','smtp.gmail.com'); if (mail($email, 'Subject','Message Goes Here', "From: <noreply@domain.com>")) { echo "Message Sent"; } else { echo "Message Not Sent"; } }//end while }// end if } } ?>
  4. i manually checked the database, the article id is inserted as i want it but there's nothing in summarized text!
  5. i have another similar problem, i cannot save the variable summary into my db $summary = SummarizeArticle($item_id); $sql2 = "INSERT INTO summarization (article_id, summarized_text) VALUES ('$item_id', '" . mysql_real_escape_string($summary) . "')"; $result2 = mysql_query($sql2) or die('Query failed: ' . mysql_error()); echo $summary; when i echo it,it is displayed correctly but when i save it it doesnt work! ony article_id is saved! any1 can help please??
  6. Everything works fine now, Thnx for the help Pikachu2000
  7. Actually its an update, so my sql should be like this: $sql1 = "UPDATE articles set original_text = '" . mysql_real_escape_string($element) . "' WHERE article_link='" . mysql_real_escape_string($item_url) . "'"; $result1 = mysql_query($sql1) or die('Query failed: ' . mysql_error()); right? but is still get the same error: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE article_link='http://www.lexpress.mu/story/20263-cour-supreme-les-accusati' at line 1
  8. I'm still not able to solve the problem. I tried mysql_real_escape but now i get this error: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE article_link='http://www.lexpress.mu/story/20263-cour-supreme-les-accusati' at line 1 Any solution please? foreach($html->find('td[class=rel_headline_cmt]') as $element) { echo $element; $sql1 = "INSERT INTO articles(original_text) VALUES ('" . mysql_real_escape_string($element) . "') WHERE article_link='" . mysql_real_escape_string($item_url) . "'"; $result1 = mysql_query($sql1) or die('Query failed: ' . mysql_error()); }
  9. Yes i get the foll. error: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'rel_headline_cmt' width='670px'>
  10. Hello Guys, I want to insert an array variable into the database e.g foreach($html->find('div[class=PostContent]') as $element) { echo $element; $sq = "INSERT INTO articles(original_text) VALUES ('$element') WHERE article_link='$item_url'"; $result = mysql_query($sql1) or die('Query failed: ' . mysql_error()); } i want to insert the variable $element into the database but i'm not able to do so for some reason! $element contains only a paragraph of text. how can i insert the variable $element?
  11. ok so i've made some changes and here's the whole codes: <?php $common_words = array( " a ", " able ", " about ", "across ", " after ", " all ", " almost ", " also ", " am ", " among ", " an ", " and ", " any ", " are ", " as " , " at ", " be ", " because ", " been ", " but ", " by ", " can ", " cannot ", " could ", " dear ", " did ", " do ", " does ", " either ", " else ", " ever ", " every ", " for ", " from ", " get ", " got ", " had ", " has ", " have ", " he ", " her ", " hers ", " him ", " his ", " how ", " however ", " i ", " if ", " in ", "into ", " is ", " it ", " its ", " just ", " least ", " let ", " like ", " likely ", " may ", " me ", " might ", " most ", " must ", " my ", " neither ", " no ", " nor ", " not ", " of ", " off ", " often ", " on ", " only ", " or ", " other ", " our ", " own ", " rather ", " said ", " say ", " says ", " she ", " should ", " since ", " so ", " some ", " than ", " that ", " the ", " their ", " them ", " then ", " there ", " these ", " they ", " this ", " tis ", " to ", " too ", " us ", " wants ", " was ", " we ", " were ", " what ", " when ", " where ", " which ", " while ", " who ", " whom ", " why ", " will ", " with ", " would ", " yet ", " you ", " your "); $title = "Japan knife attacker injures at least 13 people"; $title = strtolower($title); $title_words = array(); $new_title = str_replace($common_words, " ", $title); $title_array = explode(" ", $new_title); foreach($title_array as $word) { $title_words[] = $word; } $text = "Japanese police have arrested a man after a knife attack outside a train station that left at least 13 people injured. The man boarded two buses and attacked passengers - who were predominantly school children - in the city of Toride, some 40km (25 miles) north-east of Tokyo, reports say. Four people were stabbed, and others were injured as they fled, police say. A 27-year-old man has been arrested on suspicion of attempted murder. One of the victims would need to remain in hospital for several weeks, while the others were not seriously injured, said a spokesman for the local fire department. Correspondents say the attack has brought back memories of an incident in central Tokyo in 2008, in which a man armed with a knife killed seven people."; $sentence = strtok($text, ".?!"); $summary = ''; while ($sentence !== false){ foreach($title_words as $word) { if(strstr($sentence, $word)) { $summary .= $sentence . '. '; } } $sentence = strtok(".?!"); } echo $summary; ?> What i'm trying to do here is remove the common words from the $title then for each word in $new_title that appears in a sentence of the $text i should add that sentence to the $summary. But if more than one word from $new_title appears in a sentence that sentence is repeated the number of times the words in the $new_title appears in the text. how can i make that sentence appear only once?
  12. Hello Guys can anyone help me with this? <?php $common_words = array(" the ", " is "); $title = " The dog is chasing the boy "; $title = strtolower($title); $title_array = explode(" ", $title); $title_words = array(); foreach($title_array as $word) { $title_words[] = str_replace($common_words, " ", $title); } $text = " The dog is chasing the boy. This is an irrelevant sentence. The boy runs away from the dog. This is another irrelevant sentence. "; $sentence = strtok($text, ".?!"); $summary = ''; while ($sentence !== false){ foreach($title_words as $word) { if(strstr($sentence, $word)) { $summary .= $sentence . '. '; } } $sentence = strtok(".?!"); } echo $summary; ?> when i execute this code i get a blank page. I think the problem is on this line: $title_words[] = str_replace($common_words, " ", $title); The expected output is: The dog is chasing the boy. The boy runs away from the dog.
×
×
  • 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.