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
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

Link to comment
Share on other sites

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  :-\

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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