PHP Classes

return value of $mentions->process_text($raw_data) not working

Recommend this page to a friend!

      Mentions  >  All threads  >  return value of...  >  (Un) Subscribe thread alerts  
Subject:return value of...
Summary:How to store processed text in a variable for insert into data
Messages:1
Author:mzer terungwa
Date:2016-07-31 11:25:08
 

  1. return value of...   Reply   Report abuse  
Picture of mzer terungwa mzer terungwa - 2016-07-31 11:25:08
In trying to customize the Mentions script to fit my use case, I need to store the parsed string with highlighted names in a database. To this end, I have done this

if ($print_link == true) {
$this->print_content = "<a href=\"".$this->m_link."".$name_link."\">".$spec_w."</a>";
if ($i < count($expl_text)) $this->print_content .= " ";

} else {
$this->print_content = $spec_w;
if ($i < count($expl_text)) $this->print_content .= " ";
}
return $this->print_content;

$mentions = new mentions;
$raw_data = 'Hello, @Angelina. I am @Bob_Marley.';
$expr = '#(?:^|\W)@([\w-]+)#i';
preg_match_all($expr, $raw_data, $results);
if( !empty($results[1]) ) {

foreach( $results[1] as $user ) {
$mentions->add_name($user);
}
/*
------------------------------------
*/
echo $mentions->process_text($raw_data);
}

However this only prints out hello being the first word in the string instead of the full string. Could you provide a clue as to how I may go about returning the string to be saved in a database rather than printing on a screen.

Thanks