0

what i try to do ? i try to make code to found if there duplicate data into database or not ,that data it text Content written by users . so i make sql query to get result of row pagetext from database and clean it from any Signs And coordinate (font color, font size, and font type) and image links or any links , and same i do it for Variable $post['message'] that get Content of text area .. than i check if Content of $post['message'] is same Content of pagetext or not !

Full code :

// FUNCTION TO CLEAN TEXT
function stripBBCode($text_to_search)
{
 $pattern = '|[[\/\!]*?[^\[\]]*?]|si';
 $replace = '';
 return preg_replace($pattern, $replace, $text_to_search);
}

// MYSQL QUERY
$ckeck = $db->query_read(" SELECT pagetext FROM " . TABLE_PREFIX . " post "); 
$ckeck_num = mysql_num_rows($ckeck); 

            while ($ckeckpagetext = $db->fetch_array($ckeck))
            {

// RESULT FROM QUERY - here i try to make ARRAY BY [square brackets]
$pagetext[] = stripBBCode($ckeckpagetext['pagetext']);
$pagetext[] = preg_replace('/[\s]+/mu','', $pagetext);
$pagetext[] = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $pagetext);

// Variable 
$message = stripBBCode($post['message']);
$message = preg_replace('/[\s]+/mu','',$message );
$message = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $message);

// LOOP
for($x=0; $x<$ckeck_num; $x++)
{
// CHECK IF THERE duplicate TEXT OR NOT
if ($message == $pagetext[$x])
{
$ckeck_duplicate = 1;
}else{
$ckeck_duplicate = 2;
    }
        }
            }

My problem ? my code Almost correct , but my problem in those lines [square brackets] . when i try great array for my result

// RESULT FROM QUERY
$pagetext[] = stripBBCode($ckeckpagetext['pagetext']);
$pagetext[] = preg_replace('/[\s]+/mu','', $pagetext);
$pagetext[] = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $pagetext);

if i used only first line without used preg_replace the code works good . when i use [square brackets] for a

$pagetext[] = stripBBCode($ckeckpagetext['pagetext']);
3
  • You might want to look at this question. stackoverflow.com/questions/26449506/… Commented Oct 19, 2014 at 10:33
  • @addicted20015 I'll look at it now thnx Commented Oct 19, 2014 at 10:45
  • @addicted20015 , that's not i want .. In fact, far from what I want to do Commented Oct 19, 2014 at 10:47

2 Answers 2

0
    $pagetext = array();
    while ($ckeckpagetext = $db->fetch_array($ckeck))    
    {
        $tmpCheckPageText = stripBBCode($ckeckpagetext['pagetext']);
        $tmpCheckPageText = preg_replace('/[\s]+/mu','', $tmpCheckPageText);
        $tmpCheckPageText = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $tmpCheckPageText); 
        $pagetext[] = $tmpCheckPageText;
    }

And array is:

$pagetext = array( 'Plain text1', 'Plain text2' );
3
  • thnx but it not work too .. maybe for() loop be work ? for ($i = 0; $i < $ckeck_num; $i++){} and loop preg_replace on it $pagetext[$i] and check by if ($message == $pagetext[$i]) , what do you think ? Commented Oct 20, 2014 at 16:21
  • 1
    Is works! Show me: var_dump( $pagetext ); Check this array. If it is what You want You have all u need. Next step is check using in_array() function and $message variable. Commented Oct 20, 2014 at 17:20
  • Yes actually works, I'm sorry .. The problem was something else, a Coding, content variable $post['message'] writes in Arabic, so check not work or do not discover duplicate content . i solve the problem using iconv() like that $message = iconv("windows-1256", "UTF-8",$post['message']); thnx brother Commented Oct 21, 2014 at 2:11
0

Try Your function stripBBCode and preg_replace on variable for example $tmpCheckPageText and after this put into array $pagetext

Code:

$tmpCheckPageText = stripBBCode($ckeckpagetext['pagetext']);
$tmpCheckPageText = preg_replace('/[\s]+/mu','', $tmpCheckPageText);
$tmpCheckPageText = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $tmpCheckPageText); 
$pagetext[] = $tmpCheckPageText;

UPDATE:

Create array of pagetext from db using sql statement and purge it in while loop. For example you got this:

$pagetext = array( 'Purge Text 1', 'Purge Text 2', 'Purge text 3' );

After this, purge Your post field $message. Next check with in_array function.

echo in_array( $message, $pagetext ) ? 1 : 2;
2
  • okay that is what i want From the beginning, convert the variable $pagetext to array and use in_array ... but how i do this Create array from sql query $pagetext = array( 'Purge Text 1', 'Purge Text 2', 'Purge text 3' ); Commented Oct 19, 2014 at 12:17
  • and if i Create result on array , can i use it with preg_replace Commented Oct 19, 2014 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.