Jump to content

how can i take part of text?


janim

Recommended Posts

hello all ! ;D

i want to take part of text from mysql

let's say my page title is :

$title="php is the most common language for dynamic web pages and the most popular one";

if i want to take part of these sentence like the first 5 words to be like this

" php is the most common language..."

how can i do this

 

>>Form Database <<

 

Link to comment
https://forums.phpfreaks.com/topic/69412-how-can-i-take-part-of-text/
Share on other sites

you can try array (explode function)

 

$x= explode(' ' ,'tst df sf dsfs ff df d df df d ');

foreach($x as $key=> $val)

{

if ($key % 5 == 0){

echo '<br>';

}

echo  $val;

}

 

or

foreach($x as $key=> $val)
{
if ($key % 5 == 0){
echo '......';
break;
}
echo  $val;
}

edited...

 

or string function note: not tested but that should work

i think that this function is working but i want to use it in my index page u c ?

to start pulling data from database

so i don't wanna use while and order by id asc

i want the last inserted id in my index page

can be done ?like this

include("config.php");
mysql_connect($server, $datauser, $datapass) or die (mysql_error()); 
$last_id=mysql_insert_id();
$result = mysql_db_query($database, "select * from $table where id='$last_id'") or die (mysql_error());
if (mysql_num_rows($result)) {
  $qry = mysql_fetch_array($result);
  echo $last_id;

.
.
.
echo $qry['title'];

there is no id shown in the result and no title  :-\

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.