Category: IT
-
Check and confirm if string exist in text
<?php if( $this-artist-review ): ?<?php $word = “system-readmore”; $mystring = $this-artist-review; // Test if string contains the word if(strpos($mystring, $word) !== false){ echo “Word Found!”; } else { echo “Word Not Found!”; } ?<?php endif; ?…
-
Printing first characters of a text
This prints first 200 characters of a given text. $content = $this-artist-name; $pos = strpos($content, ‘ ‘, 200); echo substr($content,0,$pos ); …
-
Replace text in mysql table
Sometimes you need to replace some text in your Mysql database. Whatever it is (a user ID or a user name), this is the SQL query you need to run: UPDATE `table` SET `field` = REPLACE(`field`, ‘string’, ‘anothervalue’)
-
Update Mysql table
This will update data in a MySQL table whether is empty or not. UPDATE artists SET city = ‘Los Angeles’ WHERE city=’Sydney’ In this case Sydney will be replaced by Los Angeles.
-
Format 1000 to 1K and trim result to one decimal using PHP
In web design sometimes it’s neccesary to keep things short, so large numbers have to be trimmed for display. The following simple code will format any number > to 1000 to its 1K version and will limit decimals to 2 digits. $shares = $this->page->shares; $shares2 = $shares / 1000; if ($shares < 1000) { echo…
-
Showing conditional divs using php and if/else statements
If you want to show some divs instead of others on a website IF some condition is met you can use the following piece of code: php if ($artist_id == “1980”) { ?> Some data php } else { ?> Some other data <? } ?> The data and the whole layout can be different,…