can i know how to remove date part from a blogger post
for ex check the below url: http://w2t-minit.blogspot.in/2015/03/photoshop-effects-part-2.html but i want that to be like below url http://w2t-minit.blogspot.in/photoshop-effects-part-2.html
i dont want the date part “2015/03” to be posted can you help me how to remove that ??
thanks
Unfortunately, it's impossible on Blogger.
Split the absolute url, and extract the parts with REGEXP :
$url = parse_url('http://w2t-minit.blogspot.in/2015/03/photoshop-effects-part-2.html');
preg_match('#\/\d{4}\/\d{2}\/(?P<url>.*)#', $url['path'], $matches);
$matches['url'] will contain photoshop-effects-part-2.html . then re-assemble a full url :
$dateless = $url['scheme'] .'://'. $url['host'] .'/'.$matches['url'];
EDIT : I think I have misunderstood the question here.
I though is was tagged PHP...
Sure narendra,
Replace:
span#metaDetail span#datePosted {
float: left;
margin-left: 30px;
height: 32px;
line-height: 32px;
}
with:
span#metaDetail span#datePosted {
display: none;
}
Related
Need some suggestions for the methodology to achieve the following:
My current script gets text and if it has URL(s) then it replaces them. The issue is I want to truncate the URLS(s) so they do not break the width of a table or unsightly line break to fit them.
$text = file_get_contents("temp.txt");
$link = preg_replace('#(https?://([-\w\.]+)+(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?)#', '$1', $text);
echo $link;
I am concerned that if I substr() the $link then it won't work if multiple URLs are found. Can you PHP the $1 in the replacement? Any alternatives?
Use preg_replace_callback to modify the match and replacement. This returns the first 10 characters as an example:
$link = preg_replace_callback('#(https?://([-\w\.]+)+(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?)#',
function($m) {
return ''.substr($m[1], 0, 10).'';
},
$text);
This kind of problem can also be solved on client side using css (I assume you are speaking about the html element table in your question).
To do that, you have to give your cell a fixed size and to set the display property to inline-block. Then you can define the behaviour of the cell when a word is too long using the white-space, overflow and text-overflow properties.
Example:
<html>
<head>
<style>
.mytable td:nth-child(2) {
display: inline-block;
width: 200px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<table class="mytable">
<tr><td>abcd</td><td>www.smallurl.jp</td><td>efgh</td></tr>
<tr><td>ijkl</td><td>www.a-giant.url/larger/than/the/cell/width</td><td>mnop</td></tr>
</table>
</body>
</html>
I am looking to add some additional functionality to a memberlist. There are 2 files involved in this, and I need some guidance as to where this functionality should go.
File1) staff-members.php
File2) memberships.php
staff-members.php (a simple php page - that requires memberships.php to function)
<div>
<?php echo Memberships(91); ?>
</div>
As of right now (and as far as my knowledge goes), this page simply takes the array from the usergroup 91, and displays its contents on the screen.
memberships.php (This file has alot going on with it, as it is linked to vbulletin)
-I am going to try and post the snippets that I think are important to understand how the staff-members.php is populated. Let me know if you need something else
$Users = $vbulletin->db->query_read("
SELECT user.userid, userfield.field31
FROM " . TABLE_PREFIX . "user AS user
LEFT JOIN " . TABLE_PREFIX . "userfield AS userfield ON(userfield.userid = user.userid)
WHERE " . $Condition . " ORDER BY user.username ASC
if ($vbulletin->userinfo['userid'])
$Output .= '<span style="width:181px; text-align: left; display: block; float: left; font-weight: bold; color: #909090;">Username</span>';
if ($vbulletin->userinfo['userid']) {
$Output .= '<span style="width:62px; text-align: left; display: block; float: left; font-weight: bold; color: #909090;">Posts</span>';
$Output .= '<span style="width:183px; text-align: left; display: block; float: left; font-weight: bold; color: #909090;">Steam Name</span>';
$Output .= '<span style="width:100px; text-align: left; display: block; float: left; font-weight: bold; color: #909090;">Join Date</span>';
$Output .= '<span style="width:81px; text-align: left; display: block; float: left; font-weight: bold; color: #909090;">Last Activity</span>';
}
In the above code (again, as far as my knowledge) It takes the userid and username(field31) of a group and sorts them by their username.
Then it is added to $output with the formatting you see above?
Am I looking in the right places? The functionality I want is to have
Posts, Steam Name, Join Date, Last Activity clickable links on the staff-members.php page. as of right now, its only sorted by username, because of the ORDER BY in the SELECT statement. How would I go about adding this functionality?
Thank You
IF this functionality works as you have outlined the membership function will need an additional parameter added from something like
function membership(int $usergroup)
to something like
function membership(int $usergroup, $orderby, $direction)
inside the function will need some extra code added to parse the parameters like
switch($orderby)
{
case 'posts' :
$orderby = 'users.posts';
break;
case 'streamname' :
$orderby = 'users.streamname';
break;
case 'lastactivity' :
$orderby = 'users.lastactivity';
break;
case 'joinned' :
$orderby = 'users.joinedate';
break;
default :
$orderby = 'users.username';
}
switch ($direction) {
case 'DESC' :
$orderby .= ' DESC';
break;
default :
$orderby .= ' ASC';
}
The field names depend on the database structure etc to the above is not exact
then just update the SQL order by to include ORDER BY " . $orderby
the final thing to do is get the ordering from the URL so update the staff-membership.php page with
<?php
$orderby = isset($_GET['order'])?:'username';
$direction = isset($_GET['sort']?:'asc';
echo membership(91, $orderby, $direction);
?>
then in the URL add the parameters so http://example.com/staff-membership.php becomes http://example.com/staff-membership.php?order=lastactivity&sort=DESC to let the list in latest activity first
NOTE this is just a rough guide on how you might want to do this.
I have the following CSS code:
#np-toolbar-l a{ position: relative; padding: 0px 8px; line-height: 30px; display: inline-block; font-size: 12px; }
#np-toolbar-l a:hover{ background-color: #EFEFEF; opacity: 0.7; }
#np-toolbar-l a *:hover{ cursor: pointer; }
/** Icon */
#np-toolbar [class^="icon-"]{ font-size: 18px; vertical-align: middle; margin-right: 5px; }
I am trying to replace np-toolbar to another ID,
I just want to match np-toolbar not np-toolbar-l or something like this,
here's a tutoral about how to capture all the IDs from CSS:
#-?[_a-zA-Z]+[_a-zA-Z0-9-]*(?=[^}]*\{)
source: Regex to match ids in a css file?
I couldn't find out how do I search a "compelete ID" by regex,
here's my example: (It'll still count np-toolbar-l in)
/(?<=(#|\.))(np-toolbar)+(?=( |:||\[))/
EDIT: ummm, jsut added some symbols behind it,
it looks like the answer which I am looking for
/(?<=(#|\.))(np-toolbar)+(?=( |:|\[|\{|\.|,))/
If you're looking for a specific ID, you can greatly simplify your regex:
/(#np-toolbar)(?=[{.,\s])/g
That should find the ID wherever it appears in the CSS. It first matches the ID exactly, then only allows { (for beginning the style), , (for listing selectors), . (for appended classes), or space/tab/newline characters afterwards, preventing it from matching IDs like np-toolbar-1 etc.
Maybe you could try this regexp:
/#np-toolbar(?![-\w])/
which means: match all "#np-toolbar" inclusions if inclusion doesn't end with "-" or any \w symbol
I'm building the backend to a web application, where it is possible to change the design of a page. Once the user has setup the design the way they like it, they should be able to save it and the new design would be written to the specific file.
For this reason, I will need to replace all the characters between { and } after a certain string, which would be the name of the class.
So a very simple concept, say the following class was in a seperate file which I load as a view, style.php. I would need to go from:
from
<style>
.bonus {
bottom: 6px;
left: 247px;
}
</style>
to
<style>
.bonus {
bottom: 20px;
left: 450px;
}
</style>
Could someone recommend me on the best way to
a) find a string in a file,
b) when that is found, replace everything between two strings right after the first string.
Thank you.
I don't like the concept of the user making changes to the actual file very much. There are a lot of safer methods by which a user could create and maintain a custom template without them actually making changes to a PHP file.
What about storing the user's CSS in a field in a database? Then you'd simply need to do something like:
<?php
$css = getCSSByUserId($userId); //function runs query on DB to get user-specific CSS
/* $css = ".bonus {
bottom: 20px;
left: 450px;
}" */
?>
<style>
<?php echo $css; ?>
</style>
If you really want to edit the actual file, you'd do it something like this:
<?
$file = "/path/to/file.php";
//The user's replacement CSS
$replace = '.bonus {
bottom: 20px;
left: 450px;
}';
$str = file_get_contents($file);
$str = preg_replace('/\.bonus \{.*\}/U', $replace, $str);
$res = fopen($file, 'w');
fwrite($res, $str);
fclose($res);
?>
I checked the regex here http://www.quanetic.com/Regex and it works.
i'm working on a script that generates multiple CSS into one. And Here is the script.
$full_string = "";
foreach($allfiles as $curfile => $file) {
$file = $PATH[$curfile] . $file;
$file_open = fopen($file , 'r');
$concat = "\n" . fread($file_open , filesize($file)) . "\n";
$full_string .= $concat;
fclose($file_open);
}
return $full_string;
Here i'm combining all the CSS files into one. But the problem now is i have to compare the current CSS($file) with another css(let's consider it as overrider.css). And if $file is having a style like,
h1 {
color: white;
background: teal;
FONT-FAMILY: arial, helvetica, lucida-sans, sans-serif;
FONT-SIZE: 18pt;
FONT-STYLE: normal;
FONT-VARIANT: normal;
}
body
{
font-family: arial;
FONT-SIZE: 14px;
}
and if overrider.css is having a style like,
body
{
font-family: Calibri;
color: #3E83F1;
}
Then final CSS(output.css) generated should be,
h1 {
color: white;
background: teal;
FONT-FAMILY: arial, helvetica, lucida-sans, sans-serif;
FONT-SIZE: 18pt;
FONT-STYLE: normal;
FONT-VARIANT: normal;
}
body
{
font-family: Calibri;
FONT-SIZE: 14px;
color: #3E83F1;
}
Here, since style for body in override.css have font-family, it replaces the font-family property in original CSS and since the color is a new property which is not present in ($file) which is original CSS file, so it should add the property to original CSS file. So how to achieve this in PHP, since i don't have any idea on parsing CSS. Any idea on this would be greatly appreciated.
Please note that i need to generate a new CSS file by giving the input as file1($file) and file2(override.css) and we need to genrate output.css with the styles overridden.
Thanks in advance.
There are a few CSS parsers available (google "php css parser"), like this one that I didn't try, but seems interesting. But personally I'd do the parsing myself - following that kind of pseudo-PHP algorithm
read all the files into one string Str, with all "\n", "\r" and "\t" replaced by a space (to make parsing (a bit) easier)
then, function to process (selector => rules)
func deal with selectors and rules:
rules = array()
do {
S = string from current pos to next `{` excluded (selectors)
R = string from '{' to next '}' (rules)
r = explode(';', R)
lr = make array of rules from r trimmed elements
s = explode (',', S)
ls = make array of [selector => lr]
// same sel: latest rule overwrite existing, added if not exist
merge ls into rules
} while (not '}' and not '#' and not EOF); // the '}' would be the closing media
return rules
Main function to deal with medias, and then call the above function
medias = array();
func deal with Str
do {
if (first non blank char is #) {
media = array of listed medias
eat fist '{'
}
else {
media = array ('GLOBAL')
}
selectorsrules = deal with selectors and rules(rest of Str)
foreach (media as m) {
merge in medias(m) selectorsrules, same procedure as above
}
} while (not EOF);
Interesting project but I don't have the time to implement it fully. Result is in medias array.
if you want font-family: arial; to be apply then add it as font-family: arial !important;
you do not need to worry about merging them because browser will automatically add color to body tag from second css of color found in first css then it will overwrite it with second css.
You have 2 choices:
The simple way is to change your css files and add !important where it is important to be there. It is correct to have for example "body" in css more than 1 time. And whenever you a style to be overridden leave it. Ofcourse this kind of approach is mostly manual. You have to know where it will be overwritten and where not.
The second approach requires string parsing, regular expressions, and i mean you should know your way around the string ad how to parse them. You should get each of the files content, save them to a string, and you should compare them using regex to if a tag is exists in both, then merge the tags content. This way is easy to say but hard to implement.