Strip down version of field being submitted

Hi

I am a newbie to pho, still trying to learn php and mysql after programming on other database platforms for years.

I have a free package from the Internet that is workign fine, I am just trying to make some modifications to it and struggling with one part.

A php page posts a record to a mySql database with about 9 fields. One of the fields is named post_body.
I have created a new field int he database called post_body_preview.
Basically I want the page to post to this field the contents of post_body but a limited number of characters, say 150 characters.
Points to note are post_body is a html paragraph and also I would like the field to end in …

Example: If I was limiting to 10 characters, I would need

This is just a bit of text

to turn into

This is ju...

So the 10 characters that appears after

followed by ...

To make it a lot more complicated the paragraph can contain links so i would need to handle this if the first 150 characters contained a link
I wouldn’t want it to cut off half way through a link e.g. <A href="http://www.bbc.co …

if the if not included then post_body_preview will show the link code later in the process when this is presented on the site.

I would really really appreciate help with this!

I think I need a function to call to do this
There is a nother field calling a function so i can imitate this
The other field takes the Subject field, maniuplates it and posts it to a field called post_url
The code for this function is below, I need a function similar to this but does what is described above.
Can anyone help with this please?

Many thanks

[code]function create_post_url($config,$post_url,$post_id=0)
{
if (function_exists(‘mb_strtolower’))
{
$post_url = mb_strtolower($post_url);
}
else
{
$post_url = strtolower($post_url);
}
$post_url = ltrim($post_url);
$post_url = rtrim($post_url);
$post_url = preg_replace(’/\s\s+/’, ’ ‘, $post_url);
$post_url = str_replace(’ ‘,’-’,$post_url);
$post_url = str_replace(’_’,’-’,$post_url);
$post_url = htmlentities($post_url);
$post_url = preg_replace(’/&([a-zA-Z])(uml|acute|grave|circ|tilde);/’,’$1’,$post_url);
$post_url = html_entity_decode($post_url);
$post_url = preg_replace(’/[^a-z0-9-]/’, ‘’, $post_url);
$post_url = trim($post_url,’-’);
$post_url = substr($post_url,0,100);

$check_url_exists = mysql_num_rows(mysql_query("SELECT 1 FROM ".$config['db']['pre']."posts WHERE post_url='".validate_input($post_url)."' AND post_id!='".validate_input($post_id)."' LIMIT 1"));

if($check_url_exists)
{
	$count = 1;

	do
	{
		$new_post_url = $post_url.'-'.$count;
	
		$check_url_exists = mysql_num_rows(mysql_query("SELECT 1 FROM ".$config['db']['pre']."posts WHERE post_url='".validate_input($new_post_url)."' AND post_id!='".validate_input($post_id)."' LIMIT 1"));
		
		$count++;
	}
	while ($check_url_exists);
	
	$post_url = $new_post_url;
}

return $post_url;

}[/code]

Sponsor our Newsletter | Privacy Policy | Terms of Service